Normalisierung in Datenbanken (1. bis 3. Normalform)

Patrick Boekhoven
26 Nov 202111:17

Summary

TLDRDieses Video behandelt die Normalisierung in Datenbanken, die notwendig ist, um Anomalien in relationalen Datenbanken zu vermeiden. Es wird erklärt, dass Daten in der Null-Normalform in einer Tabelle unnormalisiert sind und dann nach den Regeln der ersten Normalform in atomare Attribute unterteilt werden. Weiterhin wird gezeigt, wie man mit der zweiten Normalform Tabellen erzeugt, die sicherstellen, dass jedes Nicht-Schlüsselattribut vollständig funktional von jedem Schlüssel abhängt. Es werden auch Begriffe wie Primärschlüssel und Fremdschlüssel erklärt und wie 1:n und n:n Beziehungen in relationalen Datenbanken modelliert werden.

Takeaways

  • 😀 Normalisierung ist notwendig, um Anomalien in relationalen Datenbanken zu vermeiden.
  • 🔍 Es gibt strenge Regeln für die Normalisierung, die befolgt werden müssen, um Datenbanktabellen in verschiedenen Normalformen zu erreichen.
  • 📚 Die Nullte Normalform (0NF) bedeutet, dass alle Daten in einer einzigen Tabelle unnormalisiert sind.
  • 📈 Die Erste Normalform (1NF) wird erreicht, wenn alle Attributwerte atomar sind und keine Teilbarkeiten mehr vorliegen.
  • 🔑 Die Zweite Normalform (2NF) erfordert, dass die Tabelle in 1NF ist und jedes Nicht-Schlüsselattribut vollständig funktional von jedem Kandidatenschlüssel abhängig ist.
  • 🔗 In relationalen Datenbanken wird ein Primärschlüssel verwendet, um ein Datenset eindeutig zu identifizieren.
  • 📊 Die Erstellung von Untertabellen hilft, die Anforderungen der 2NF zu erfüllen, indem nicht-schlüsselbezogene Daten in separate Tabellen ausgelagert werden.
  • 🔄 Die Beziehungen zwischen Tabellen, wie 1:n oder n:m, werden durch Fremdschlüssel und zusätzliche Tabellen modelliert, um die Normalformen zu gewährleisten.
  • 📝 Die Erklärung der Normalformen hilft, Datenredundanzen und Anomalien zu vermeiden und die Datenintegrität beizubehalten.
  • 💡 Die Anwendung der Normalisierungsregeln ist ein wichtiger Schritt im Datenbankdesign, um die Effizienz und Zuverlässigkeit der Datenspeicherung zu verbessern.

Q & A

  • Was ist Normalisierung in der Datenbank-Design?

    -Normalisierung ist ein Prozess im Datenbank-Design, der darauf abzielt, Anomalien in relationalen Datenbanken zu vermeiden, indem Daten redundant und gut strukturiert gespeichert werden.

  • Welche Art von Anomalien werden durch Normalisierung vermieden?

    -Durch Normalisierung werden Anomalien wie Update-Anomalien, Einfüge-Anomalien und Löschanomalien vermieden, die auftreten können, wenn Daten nicht korrekt in einer Datenbank organisiert sind.

  • Was ist die Bedeutung von 'atomaren' Attributwerten in Bezug auf die erste Normalform?

    -In der ersten Normalform (1NF) müssen alle Attributwerte atomar sein, d.h., sie dürfen nicht weiter in kleinere Bestandteile unterteilt werden, um eine konsistente und redundantenfreie Datenstruktur zu gewährleisten.

  • Wie wird die erste Normalform erreicht?

    -Um eine Tabelle in die erste Normalform zu bringen, müssen alle Attributwerte atomar sein und die Tabelle darf keine zusammengesetzten Attributgruppen enthalten, die in mehrere Spalten aufgeteilt werden müssen.

  • Was ist die Bedeutung von 'Schlüsselkandidaten' in der zweiten Normalform?

    -Schlüsselkandidaten sind Attribute oder eine Kombination von Attributen, die genutzt werden können, um eindeutig Datensätze in einer Tabelle zu identifizieren. Sie sind entscheidend für die Erreichung der zweiten Normalform (2NF).

  • Was bedeutet es, wenn eine Tabelle in der zweiten Normalform ist?

    -Eine Tabelle ist in der zweiten Normalform, wenn sie die Bedingungen der ersten Normalform erfüllt und jedes Nicht-Schlüsselattribut vollständig funktional von jedem Schlüsselkandidaten abhängig ist.

  • Wie wird die Beziehung zwischen Tabellen in relationalen Datenbanken dargestellt?

    -In relationalen Datenbanken werden Beziehungen durch Fremdschlüssel dargestellt. Ein Fremdschlüssel in einer Tabelle verweist auf den Primärschlüssel einer anderen Tabelle, um die Verbindung zwischen den Tabellen herzustellen.

  • Was ist eine 1:n-Beziehung in relationalen Datenbanken?

    -Eine 1:n-Beziehung (eins-zu-vielen) bedeutet, dass ein Datensatz in der Haupttabelle (z.B. ein Kunde) mehrere zugehörige Datensätze in der verknüpften Tabelle haben kann (z.B. mehrere Bestellungen), während ein Datensatz in der verknüpften Tabelle nur einem Datensatz in der Haupttabelle zugeordnet werden kann.

  • Was ist eine n:n-Beziehung und wie wird sie in relationalen Datenbanken gehandhabt?

    -Eine n:n-Beziehung (vielen-zu-vielen) bedeutet, dass ein Datensatz in einer Tabelle (z.B. ein Artikel) mehrere Datensätze in einer anderen Tabelle haben kann (z.B. mehrere Bestellungen) und umgekehrt. Um diese Beziehung zu verwalten, wird eine neue Tabelle erstellt, die Fremdschlüssel von beiden Tabellen als zusammengesetzten Primärschlüssel enthält.

  • Was sind die Schritte, um eine Tabelle in die dritte Normalform zu bringen?

    -Um eine Tabelle in die dritte Normalform zu bringen, muss die Tabelle bereits in der zweiten Normalform sein und jedes Nicht-Schlüsselattribut muss nur von dem Primärschlüssel und nicht von einem Teil des Primärschlüssels abhängen.

  • Was ist der Zweck von Normalisierung in Datenbanken?

    -Der Zweck der Normalisierung in Datenbanken ist es, redundanzfreie, gut organisierte und leicht zu verwaltende Datenstrukturen zu schaffen, die es ermöglichen, Datenanomalien zu vermeiden und die Datenintegrität zu gewährleisten.

Outlines

00:00

😀 Datenbanknormalisierung Einführung

Dieses Video behandelt das Thema der Datenbanknormalisierung, die notwendig ist, um Anomalien in relationalen Datenbanken zu vermeiden. Es wird auf ein bereits veröffentlichtes Video verwiesen, das Anomalien und ihre Probleme erklärt. Die Normalisierung dient der Datenbankgestaltung und soll Anomalien und Redundanzen verhindern. Der Einstieg erfolgt mit der Nullten Normalform, die durch eine Tabelle ohne Normalisierung gekennzeichnet ist. Das Beispiel der Computerfirma HyperEDV zeigt, wie Daten in einer Tabelle zusammengefasst werden. Die Umwandlung in die Erste Normalform erfordert, dass alle Attributwerte atomar sind, was bedeutet, dass sie nicht weiter zerlegt werden können. Beispielsweise müssen der Name in Vor- und Nachname aufgeteilt werden, um eine effiziente Sortierung und Filterung zu ermöglichen.

05:00

📚 Von der Nullten zur Ersten Normalform

Die Umwandlung der Datenbanktabelle in die Erste Normalform beinhaltet die Trennung von zusammengefassten Attributen in atomare Bestandteile. Hierbei wird die Adresse beispielsweise in Straße, Ort und Postleitzahl aufgeteilt, um eine klare Zuordnung und effiziente Datenverwaltung zu gewährleisten. Es wird betont, dass die Trennung so weitgehend wie möglich durchgeführt werden muss, ohne jedoch unnötige Unterteilungen vorzunehmen, die keine praktischen Vorteile bringen, wie etwa die Trennung der Hausnummer, wenn diese für keine weitere Verwendung erforderlich ist.

10:04

🔑 Die Zweite Normalform und Schlüssel

Der zweite Abschnitt des Skripts konzentriert sich auf die Zweite Normalform, die die Bedingung aufstellt, dass jeder Nicht-Schlüsselattribut vollständig funktional abhängig vom Schlüsselkandidaten sein muss. Hierbei wird erläutert, dass jede höhere Normalform auf der vorherigen basiert und dass die Erstellung von Primärschlüsseln in relationalen Datenbanken dazu dient, Datensätze eindeutig zu identifizieren. Durch die Trennung in verschiedene Tabellen, wie z.B. Kunden, Bestellungen und Artikelnummer, werden die Beziehungen zwischen den Daten klarer und die Datenintegrität gewährleistet. Die Verwendung von zusammengesetzten Primärschlüsseln in der Tabelle 'OrderArticle' verdeutlicht die Notwendigkeit, beide Informationen zusammen zu betrachten, um sinnvolle Daten zu erhalten.

🔗 Beziehungen in relationalen Datenbanken

Dieses Kapitel erklärt die Beziehungen zwischen Tabellen in relationalen Datenbanken, insbesondere die 1:n-Beziehung zwischen Kunden und Bestellungen sowie die n:n-Beziehung zwischen Artikeln und Bestellungen. Es wird verdeutlicht, wie durch die Verwendung von Fremdschlüsseln in der Bestellungen-Tabelle die 1:n-Beziehung zwischen Kunden und ihren Bestellungen modelliert wird. Für die n:n-Beziehung wird die Notwendigkeit einer neuen Tabelle hervorgehoben, die die Beziehung zwischen Artikeln und Bestellungen abbildet und somit die Flexibilität und Effizienz der Datenbank erhöht.

Mindmap

Keywords

💡Normalisierung

Normalisierung ist ein Prozess im Datenbankdesign, der darauf abzielt, Anomalien in relationalen Datenbanken zu vermeiden. Im Video wird erläutert, dass sie dazu beiträgt, Redundanzen und inkonsistente Daten zu reduzieren. Ein Beispiel dafür ist die Umwandlung von Daten in der dritten Normalform, um sicherzustellen, dass jeder Datenwert genau einmal vorkommt und vollständig funktional von den Schlüsseln abhängt.

💡Anomalie

Anomalien beziehen sich auf Probleme, die in nicht normalisierten Datenbanken auftreten können, wie z.B. Datenredundanz, Datenverlust und inkonsistente Daten. Im Video wird erklärt, dass Normalisierung dazu dient, solche Anomalien zu vermeiden, indem Daten in eine formale Struktur gebracht werden, die diese Probleme reduziert.

💡Zero Normalform

Die Zero Normalform (0NF) ist ein Ausgangspunkt in der Datenbank-Normalisierung, bei dem alle Daten in einer einzigen Tabelle gespeichert sind, ohne besondere Struktur. Im Video wird die HyperEDV-Datenbank als Beispiel verwendet, um zu zeigen, wie Daten in der 0NF unstrukturiert sind und wie sie in die erste Normalform konvertiert werden müssen.

💡Erste Normalform

Die erste Normalform (1NF) erfordert, dass alle Attribwerte atomar sind, d.h., sie können nicht weiter in kleinere Bestandteile unterteilt werden. Im Video wird gezeigt, wie die Tabelle von der 0NF in die 1NF transformiert wird, indem z.B. der Name in Vor- und Nachname aufgeteilt wird, um die Sortierung und Suche nach Kunden zu erleichtern.

💡Atomar

Atomarität bezieht sich auf die Eigenschaft von Attribwerten, die nicht weiter in kleinere Einheiten unterteilt werden können. Im Video wird dies anhand des Beispiels des Namens-Attributs veranschaulicht, das in Vor- und Nachname aufgeteilt wird, um die Atomarität zu erreichen.

💡Zweite Normalform

Die zweite Normalform (2NF) erfordert, dass eine Tabelle in 1NF ist und jedes Nichtschlüsselattribut vollständig funktional von jedem Schlüsselkandidaten abhängt. Im Video wird erklärt, wie durch die Trennung von Tabellen, z.B. in Kunden-, Aufträge- und Artikeltabellen, sichergestellt wird, dass die 2NF-Regeln erfüllt sind.

💡Schlüsselkandidaten

Schlüsselkandidaten sind Attribute oder eine Kombination von Attributen, die verwendet werden können, um eindeutig Datensätze in einer Tabelle zu identifizieren. Im Video wird gezeigt, wie z.B. die Kundennummer, Artikelnummer und Auftragsnummer als Schlüsselkandidaten für die jeweiligen Tabellen fungieren.

💡Primärschlüssel

Ein Primärschlüssel ist ein Schlüsselkandidaten, der als eindeutige Identifikation für Datensätze in einer Tabelle verwendet wird. Im Video wird erläutert, dass Primärschlüssel, wie z.B. die Kundennummer, nur einmal vorkommen dürfen und somit die Eindeutigkeit der Datensätze gewährleisten.

💡Fremdschlüssel

Ein Fremdschlüssel ist ein Schlüssel in einer Tabelle, der als Schlüssel in einer anderen Tabelle vorkommt und eine Beziehung zwischen den Tabellen herstellt. Im Video wird beschrieben, wie der Primärschlüssel in der Kundentabelle als Fremdschlüssel in der Auftragstafel verwendet wird, um die 1:n-Beziehung zu repräsentieren.

💡1:n-Beziehung

Eine 1:n-Beziehung (eins-zu-vielen) ist eine Beziehung zwischen Tabellen, bei der ein Datensatz in der Quelltabelle einer beliebigen Anzahl von Datensätzen in der Zieltabelle zugeordnet werden kann. Im Video wird dies anhand der Beziehung zwischen Kunden und Aufträgen veranschaulicht, wobei jede Kundennummer in der Auftragstafel mehrere Aufträge haben kann.

💡n:m-Beziehung

Eine n:m-Beziehung (vielen-zu-vielen) ist eine Beziehung, bei der Datensätze in beiden Tabellen mehreren Datensätzen in der jeweils anderen Tabelle zugeordnet werden können. Im Video wird erklärt, dass für eine n:m-Beziehung, wie die zwischen Aufträgen und Artikeln, eine neue Tabelle benötigt wird, um diese Beziehung zu verwalten.

Highlights

The video discusses the concept of normalization in databases to prevent anomalies.

Normalization is a database design technique aimed at avoiding redundancies and anomalies.

The video provides a step-by-step explanation of the normalization rules.

Zeroth normal form is characterized by all data being unnormalized in a single table.

The first normal form requires that all attribute values must be atomic.

Breaking down the 'name' attribute into 'first name' and 'last name' is an example of achieving atomicity.

Addresses should be divided into 'street', 'place', and 'postal zip code' for better database structure.

The importance of distinguishing between atomic and non-atomic data for database efficiency is highlighted.

Second normal form involves ensuring every non-key attribute is fully functionally dependent on the key candidate.

Primary keys are essential for identifying data sets uniquely in relational databases.

The concept of fully functional dependencies is introduced to explain second normal form.

The video demonstrates the creation of four tables to achieve second normal form.

Composite primary keys are used in the 'OrderArticle' table to handle complex relationships.

The necessity of separating non-key attributes into sub-tables for second normal form is explained.

The video clarifies the 1 to n relationship between the 'Customer' and 'Order' tables.

The handling of n to n relationships requires a new table to maintain database integrity.

The video concludes by discussing the practical applications of normalization in database management.

Transcripts

play00:11

In this video we will deal with the topic of normalization from the field of databases.

play00:16

Normalization is necessary to avoid anomalies in relational databases.

play00:19

I have already made a video on this topic, or rather, I have already shown what anomalies

play00:25

are and what problems they lead to.

play00:28

I link the video above.

play00:29

Again and again this leads to problems or difficulties.

play00:31

But it is enough to remember the rules and just apply them.

play00:35

I will explain these rules to you step by step.

play00:40

And it should be said that the normalization is a database design and has the sense to

play00:50

prevent anomalies and redundancies.

play00:51

We will start with the zeroth normal form and for this purpose we will

play00:57

we will look at the database of the computer company hyperEDV, which has a database, but

play01:03

it is still renormalized.

play01:04

In a database of the zeroth normal form, all the data is unnormalized in a single table.

play01:10

And this is exactly the case here.

play01:11

Our database consists of a single table with order number, name, date of birth, etc..

play01:16

And as you can see, this doesn't look very good and shouldn't stay that way, which is

play01:22

why we convert the tables to the first

play01:26

into the first normal form.

play01:27

I already said, there are always quite rigid rules for normalization that have to be followed

play01:32

and the same applies here.

play01:33

The rule to convert tables into the first normal form is: "All attribute values must

play01:39

be atomic".

play01:40

By an

play01:41

attribute itself we mean a column like OrderNo or the name.

play01:45

And by atomic we mean that we cannot break down these attributes further.

play01:49

This is not the case here at the moment, because our table is still in the zeroth normal form

play01:59

and we are now looking at the name, for example.

play02:04

Our customers have a first

play02:06

and a surname and this means that we have to break down these columns as far as possible.

play02:12

possible.

play02:13

We make two new columns out of the name column, namely first name and last name.

play02:20

Because only in this way we can sort by last name at the end and display all customers

play02:25

who begin with an S in the last name, because our computer would not know if Ludger Sievert

play02:28

is in a cell, how it should divide the whole thing.

play02:30

where does the last name begin here, or what is the first name or what is

play02:35

the last name.

play02:36

The same still applies to the address.

play02:38

also the address we would have to divide still into the attributes street, place or postal

play02:44

zip code, because also the computer does not know, how can one distinguish here between

play02:51

street, place and postal zip code.

play02:52

For example, if we display all customers from Münster and

play02:56

they are in one field, this is not very convenient.

play02:58

Means; we must divide everything so WIDE that everything in a single column is atomically

play03:03

in a single column.

play03:05

And then I would say, let's do that and take a look at the result.

play03:09

And yes the attentive ones among you will notice now the house number one could divide

play03:14

nevertheless also still.

play03:15

Of course you could and that would be absolutely correct according to the rule.

play03:18

But we neither want to sort by the house number nor do anything with the house number.

play03:22

That's why it doesn't give us a big advantage.

play03:27

Here it is of course always a question of weighing up whether it makes sense or not,

play03:30

but if we were to apply the rule in this way.

play03:32

Then we would have to transfer the house number of course also in an own column.

play03:40

So far clear?

play03:42

The rule is relatively easy to apply.

play03:44

And we have, if we don't see it strictly, a table in the first

play03:48

normal form.

play03:49

We continue this with the second normal form and for this we look as usual first at the

play03:52

definition which is needed for

play03:55

the second normal form.

play03:56

The rule is as follows: A table is in second normal form if it is in first normal form

play04:02

and every non-key attribute is fully functionally dependent on each key

play04:07

candidate.

play04:08

This sounds a bit more complicated than it actually is.

play04:11

Because it

play04:12

is not

play04:13

that complicated at all.

play04:14

We will notice that now.

play04:16

As first information is important that each normal form requires the previous

play04:21

normal form, as with the second one.

play04:25

Means, if we want to have a table in the second normal form or transfer it to the second the

play04:35

table must first be in the first first normal form.

play04:39

And then we can we can bring the table into the second normal form.

play04:42

This rule is also valid for the third normal form.

play04:47

Means, there the table must be first in the in the second normal form.

play04:51

Now let's look further, because for the second

play04:54

normal form we make a small excursion in relational databases.

play04:57

In relational databases we work with primary keys.

play05:00

The purpose of a key in a relational database, a key is used to identify a data set without

play05:07

identified without any doubt and this value may therefore only occur once.

play05:12

Our

play05:13

primary keys can be recognized by the fact that

play05:16

the columns above are underlined like customer number and

play05:19

order number are underlined.

play05:21

For this one or maybe more columns

play05:23

are defined, which take over this task.

play05:25

For an order for example we can

play05:26

we can well imagine the order number for this.

play05:29

An order has a number and this number

play05:31

is unique.

play05:32

It does not exist more than once.

play05:34

There is nothing to do with it.

play05:37

The same

play05:38

applies to the customer and to all articles.

play05:41

Here, too, the customer number or article number

play05:43

the article number is unique.

play05:44

Each customer has its own number and each article has

play05:46

its own number.

play05:47

And now we turn our attention to the to the story of the fully functional

play05:53

dependencies.

play05:54

We now get a total of four tables as you can see, which have been

play05:59

created

play06:00

one table at the beginning.

play06:01

These are

play06:02

Order, Customer, Article and OrdersArticle.

play06:03

We will now look step by step at

play06:06

why these tables have been created in this form

play06:08

and how we deal with them.

play06:13

Each of these

play06:15

tables in a relational database has a primary key and non-key attributes

play06:19

which in the second normal form are fully functionally

play06:25

depend on primary keys.

play06:26

We look at

play06:28

at the customer, for example.

play06:32

Since the first name is fully functionally dependent

play06:36

to the customer ID.

play06:37

We can see this even better in the table OrderArticle.

play06:47

Here we use

play06:48

we use a composite primary key of order number and article number.

play06:52

So

play06:53

both columns form the primary key here.

play06:57

Order and article must not appear together in this

play07:02

must not occur again in this table.

play07:04

In addition there is the column number, which and there one can

play07:08

you can see it relatively well, equally from the order number as well as from the

play07:14

article number

play07:16

as well.

play07:17

So we always need both information.

play07:21

So the order number and

play07:24

the article number together so that the number is meaningful.

play07:33

That means, the number

play07:34

is fully functionally dependent to the whole primary key.

play07:40

So we have each column

play07:42

that was not fully functionally dependent on a key kanidata

play07:46

from a key channel data in the previous table into a

play07:50

sub-table.

play07:51

We remember, we had our own key candidates, respectively

play07:54

the article number, customer number and order number

play07:57

in one table and now we have moved them to

play08:00

into their own tables, which is normal in the second normal form.

play08:06

normal form.

play08:08

Now you ask yourselves

play08:11

how do we get the second customer number and the second

play08:20

we get the second customer number and the second

play08:26

article number and the second order number.

play08:32

We will now look at this in detail.

play08:36

Let's have a look at the relationship between the Customer table and

play08:44

the Order table and the relationship between the table Order, OrderArticle

play08:50

and Article and the table OrderArticle table.

play08:53

Let's start first with the order

play08:56

and the customer and we can see that the customer number

play09:02

appears in the Order table.

play09:05

Here

play09:06

is a relationship between the the Customer table and the Purchase Order

play09:10

table

play09:11

and it is a 1 to n

play09:21

relationship.

play09:22

The 1 means in this case,

play09:27

that each order can have one or no customer customer.

play09:33

And the n means that each customer has not made one or more orders.

play09:43

orders.

play09:44

This is resolved in relational databases so that the primary key on the

play09:55

on the customer side acts as a foreign key in the

play10:04

Order table.

play10:05

Thus each

play10:07

order number can only appear once, since the Order number column is the primary key

play10:14

and the customer can appear multiple times and can have multiple purchase orders.

play10:25

Thus we solve

play10:26

only one to n relationship in relational databases.

play10:29

databases.

play10:30

now here we have

play10:31

a second relationship and this one is a bit more complicated.

play10:37

Here we are dealing with an

play10:39

n to n relationship.

play10:40

If we have a 1 to n relationship, as we have just seen, the primary key

play10:53

as a foreign key in the other table we need a new table for an

play11:05

n to n relationship we need a new table in any case.

play11:11

The n to n relationship says that an item can have

play11:14

can have several orders and an order can have

play11:16

several articles

Rate This

5.0 / 5 (0 votes)

Ähnliche Tags
DatennormalisierungRelationale DatenbankenAnomalienDatenqualitätDatenmodellierung1NF2NFPrimärschlüsselFremdschlüsselTabellenstrukturDatenredundanz