26
Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen • Normalisieren • Schlüssel

Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Embed Size (px)

Citation preview

Page 1: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 1

WorzykFH Anhalt

6 Normalformen

• Normalisieren

• Schlüssel

Page 2: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 2

WorzykFH Anhalt

Datenmodell

Das Entwickeln einer Anwendung mit Hilfe einer relationalen Datenbank erfordert die Entwicklung eines Datenmodells, das möglichst exakt die zu bearbeitenden Daten der realen Welt widerspiegelt.

Page 3: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 3

WorzykFH Anhalt

DatensammlungMatr Name Vor-

lesungStudiengang

Studiendauerbis jetzt

Semester Regel-studienzeit

Note

98001 J utta Math Inf 1 2 9 1.398002 Emil Prog FÜ 2 4 8 1.798003 Fritz DatOrg Inf 2 4 9 2.097001 Anna Math FÜ 1 2 8 4.097002 Else Prog IM 2 4 10 2.398004 Hans DBS1 Inf, IM 398001 J utta Prog Inf 1 2 9 2.7

Page 4: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 4

WorzykFH Anhalt

Gründe für das Normalisieren

• Vermeidung unerwünschter Abhängigkeiten bei Datenmanipulationen

• Gundlage für ein leicht erweiterbares Datenmodell

• Verständliches Datenmodell• Elimination von Redundanzen• Systematisches Auseindersetzen mit den

Daten

Page 5: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 5

WorzykFH Anhalt

Funktionale Abhängigkeit

In der Relation R(A,B) ist das Attribut B von dem Attribut A funktional abhängig, falls zu jedem Wert von A genau ein Wert von B gehört.

A wird Determinante von B genannt.Beispiel:

Studiengang Regelstudienzeit

Page 6: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 6

WorzykFH Anhalt

Volle funktionale Abhängigkeit

In der Relation R(S1, S2, A) ist das Attribut A von den Attributen S1, S2 voll funktional abhängig, wenn A von den zusammengesetzten Attributen (S1, S2) abhängig ist, nicht aber von je einem einzelnen Attribut S1 oder S2.

Beispiel: Name Vorlesung Note Jutta Mathematik 1.3 Emil Programmierung 1.7

Page 7: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 7

WorzykFH Anhalt

Transitive AbhängigkeitIn der Relation R(S, A, B) ist das

Attribut B transitiv von S abhängig, wenn A von S funktional abhängig ist, aber S nicht von A; und B ist funktional von A abhängig ist.

Beispiel: Name Studiengang Regelstudienzeit J utta Informatik 9 Emil Fachübersetzen 8

Page 8: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 8

WorzykFH Anhalt

Berechnete Attribute

Beispiel:

Name Studiendauer Semester J utta 1 2 Emil 2 4 Hans 1.5 3

Page 9: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 9

WorzykFH Anhalt

Schlüssel

Sei X = {A1, ..., An} die Menge aller Attribute einer Relation R(A1,..., An).

Eine Teilmenge SX von Attributen ist ein Schlüsselkandidat, wenn gilt:

X ist funktional von S abhängigDie funktionale Abhängigkeit gilt nicht

für eine echte Teilmenge von S

Page 10: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 10

WorzykFH Anhalt

Schlüssel

Eigenschaften eines Schlüssels

– eindeutig

– unmittelbar zuteilbar

– kurz

– schreibbar

Page 11: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 11

WorzykFH Anhalt

Sprechende Schlüssel

Der Schlüssel enthält einen Hinweis auf das Tupel, das er identifiziert

Vorteil: leicht zu merken für eine manuelle Bearbeitung der Tupel

Nachteil: Bei der Änderung eines Attributs des Tupels kann sich der Schlüssel ändern

Page 12: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 12

WorzykFH Anhalt

Sprechende SchlüsselBeispiel

Identifikation eines Personaldatensatzes über den Personennamen

Vorteil: leicht zu merkenNachteil:

– Zwei Personen gleichen Namens– Namensänderung – komplizierte Namen

Page 13: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 13

WorzykFH Anhalt

Verdeckter SchlüsselBeispiel

Der Schlüssel wird nur für datenbankinterne Kennzeichnung benutzt und bleibt dem Anwender verborgen

Beispiel:– mehrsprachiger Katalog– Fehlermeldungen

Page 14: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 14

WorzykFH Anhalt

Künstlicher SchlüsselBeispiel

Der Schlüssel wird bei Bedarf vom Rechner generiert. Der Anwender hat keinen Einfluß auf den Wert des Schlüssels.

Beispiel: fortlaufend generierte Martikel Nummer

Page 15: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 15

WorzykFH Anhalt

SchlüsselkandidatenMatr Name Vor-

lesungStudiengang

Studiendauerbis jetzt

Semester Regel-studienzeit

Note

98001 J utta Math Inf 1 2 9 1.398002 Emil Prog FÜ 2 4 8 1.798003 Fritz DatOrg Inf 2 4 9 2.097001 Anna Math FÜ 1 2 8 4.097002 Else Prog IM 2 4 10 2.398004 Hans DBS1 Inf, IM 398001 J utta Prog Inf 1 2 9 2.7

Page 16: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 16

WorzykFH Anhalt

Erste Normalform

Eine Relation ist in der ersten Normalform (1NF), wenn alle Attribute nur atomare Werte enthalten.

Beispiel für eine Relation, die nicht in der ersten Normalform ist: Name Vorlesung Studiengang

Hans DBS1 Inf, IM

Page 17: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 17

WorzykFH Anhalt

Zweite Normalform

Eine Relation ist in der zweiten Normalform (2NF), wenn sie in der 1NF ist und jedes Nicht-Schlüssel-Attribut voll funktional abhängig ist vom Gesamtschlüssel.

Page 18: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 18

WorzykFH Anhalt

Beispiel nicht zweite Normalform

Matr Vorlesung Note Studiengang98001 Math 1.3 Inf98002 Prog 1.7 FÜ98003 DatOrg 2.0 Inf97001 Math 4.0 FÜ97002 Prog 2.3 IM98004 DBS1 Inf98001 Prog 2.7 Inf

Page 19: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 19

WorzykFH Anhalt

Dritte Normalform

Eine Relation ist in der dritten Normalform (3NF), wenn sie in der 1NF und der 2NF ist und keine transitiven Abhängigkeiten enthält.

Page 20: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 20

WorzykFH Anhalt

Beispiel nicht dritte Normalform

Matr Vorlesung Note98001 Math 1.3 sehr gut98002 Prog 1.7 gut98003 DatOrg 2.0 gut97001 Math 4.0 ausreichend97002 Prog 2.3 gut98004 DBS198001 Prog 2.7 befriedigend

Page 21: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 21

WorzykFH Anhalt

NormalisierenDatensammlung:

Matr Name Addr Vor-lesung

Stg. Sem Regel Note

98001 J utta WH1 Math Inf 2 9 1.398002 Emil WH1 Prog FÜ 4 8 1.798003 Fritz WH4 DatOrg Inf 4 9 2.097001 Anna WH5 Math FÜ 2 8 4.097002 Else WH2 Prog IM 4 10 2.398004 Hans WH4 DBS1 Inf, IM 2, 2 9, 10 4.7, 2.098001 J utta WH1 Prog Inf 2 9 2.7

Page 22: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 22

WorzykFH Anhalt

NormalisierenNicht-atomare Einträge auflösen:

Matr Name Addr Vor-lesung

Stg. Sem Regel Note

98001 J utta WH1 Math Inf 2 9 1.398002 Emil WH1 Prog FÜ 4 8 1.798003 Fritz WH4 DatOrg Inf 4 9 2.097001 Anna WH5 Math FÜ 2 8 4.097002 Else WH2 Prog IM 4 10 2.398004 Hans WH4 DBS1 Inf 2 9 4.798004 Hans WH4 DBS1 IM 2 10 2.098001 J utta WH1 Prog Inf 2 9 2.7

Page 23: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 23

WorzykFH Anhalt

NormalisierenSchlüsel suchen :

Matr Name Addr Stg. Sem Regel98001 J utta WH1 Inf 2 998002 Emil WH1 FÜ 4 898003 Fritz WH4 Inf 4 997001 Anna WH5 FÜ 2 897002 Else WH2 IM 4 1098004 Hans WH4 IM 2 10

Matr Vor-lesung

Stg Note

98001 Math Inf 1.398002 Prog FÜ 1.798003 DatOrg Inf 2.097001 Math FÜ 4.097002 Prog IM 2.398004 DBS1 Inf 4.798004 DBS1 IM 2.098001 Prog Inf 2.7

Page 24: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 24

WorzykFH Anhalt

NormalisierenTransitive Abhängigkeiten auflösen :

Matr Name Adr Stg. Sem98001 J utta WH1 Inf 298002 Emil WH1 FÜ 498003 Fritz WH4 Inf 497001 Anna WH5 FÜ 297002 Else WH2 IM 498004 Hans WH4 IM 2

Matr Vor-lesung

Note

98001 Math 1.398002 Prog 1.798003 DatOrg 2.097001 Math 4.097002 Prog 2.398004 DBS1 4.798004 DBS1 2.098001 Prog 2.7Stg. Regel

Inf 9FÜ 8IM 10

Page 25: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 25

WorzykFH Anhalt

Normalisieren

Normalize until it hurtsDenormalize until it works

Page 26: Datenbanksysteme für FÜ SS 2000 Seite 4 - 1 Worzyk FH Anhalt 6 Normalformen Normalisieren Schlüssel

Datenbanksysteme für FÜ SS 2000Seite 4 - 26

WorzykFH Anhalt

Zusammenfassung

• Normalisieren ist eine Bottom-Up Methode zum strukturieren der Daten

• Die 3NF hat keine funktionalen und transitiven Abhängigkeiten