Sie sind auf Seite 1von 29

Example2

First Normal Form

First Normal Form: No repeating groups.

This violates the first normal form, and would result in large
rows, wasted space (where an invoice had less than the maximum
number of line items).
First form normalization requires you make a separate line item
table, with it's own key (in this case the combination of invoice
number and line number).
First form normalization
Second Normal Form

Second Normal Form: A table is in second normal form (2NF)


if it is in first normal form and no non-key attribute is
dependent on only a portion of the primary key.

Each attribute must depend on the *entire* primary key.


Each attribute must depend on the *entire* primary key.

Putting customer information in the line item table will cause


redundant data, with it's inherent overhead and difficult
modifications
Second form normalization requires you place the customer
information in the invoice table (see below).
Second form normalization
Third Normal Form

Second Normal Form: A table is in third normal form (3NF) if


it is in second normal form and Each attribute depend on
*directly* on the primary key.
Third form
normalization
Example3
Underlined attributes represent the primary key
Italicized attributes represent members of repeating groups

Order Number, Order Date, Customer Number, Customer Name,


Part Number, Part Description, Amount Ordered

A relation (table) is in first normal form (1NF) if it does


not contain repeating groups.
Order Number, Order Date, Customer Number, Customer Name,
Part Number, Part Description, Amount Ordered

First form
normalization

Order Number, Order Date, Customer Number, Customer Name

Order Number, Part Number, Part Description, Amount Ordered


A relation is in second normal form (2NF) if it is in first
normal form and no non-key attribute is dependent on
only a portion of the primary key.

Order Number, Order Date, Customer Number, Customer Name

Order Number, Part Number, Part Description, Amount Ordered


Order Number, Part Number, Part Description, Amount Ordered

Second form
normalization

Part Number, Part Description

Order Number, Part Number, Amount Ordered


A relation is in third normal form (3NF) if it is in second
normal form and No non-key attributes depend on other
non-key attributes

Order Number, Order Date, Customer Number, Customer Name

Part Number, Part Description

Order Number, Part Number, Amount Ordered


Order Number, Order Date, Customer Number, Customer Name

Third form
normalization

Order Number, Order Date, Customer Number

Customer Number, Customer Name


Example 4
Our Table
user

name name phone1 phone2 email1 email2


nickname
phone1 Mike 403-555- 403-555- mike@hoppen.c mhillyer@mysite.
phone2
phone3
Hillyer 1717 1919 om com
cell
pager
address
Tom 403-555- 403-555- tom@openwin.or tom@supersite.or
city Jensen 1919 1313 g g
province
postal_code
country Ray Smith 403-555- 403-555- ray@cpma.com
email1
email2 1919 1111
web_url
company
department
picture
notes
email_format
First Normal Form
Remove horizontal redundancies •
No two columns hold the same information –
No single column holds more than a single item –
Each row must be unique •
Use a primary key –
Benefits •
Easier to query/sort the data –
More scalable –
Each row can be identified for updating –
One Solution
user

first_na last_nam phone email


first_name
last_name me
Mike e
Hillyer 403-555- mike@hoppen.com
nickname 1717
phone Mike Hillyer 403-555- mhillyer@mysite.com
cell
pager
Tom Jensen 1919
403-555- tom@openwin.org
address Tom Jensen 1919
403-555- tom@supersite.org
city
province Ray Smith 1313
403-555- ray@cpma.com
postal_code
country Ray Smith 1919
403-555-
web_url
department 1111
picture
notes

• Multiple rows per user


• Emails are associated with only one other phone
• Hard to Search
Satisfying 1NF
user

PK user_id

first_name
last_name
phone
nickname email
address PK phone_id
city PK email_id
province country_code
postal_code address number
country extension
web_url
company
department
picture
notes
Forming Relationships
Three Forms •
One to (zero or) One –
One to (zero or) Many –
Many to Many –
One to One •
?Same Table –
One to Many •
Place PK of the One in the Many –
Many to Many •
Create a joining table –
Joining Tables

user phone
user_phone
PK user_id PK phone_id
PK,FK1 phone_id
PK user_id
first_name country_code
last_name number
type
nickname extension
address
city
province
postal_code
country email
web_url
PK address
picture
notes
FK1 user_id
email_format
Our User Table
first_na last_nam company department
me
Mike e
Hillyer MySQL Documentation
Tom Jensen CPNS Finance
Ray Smith CPNS Documentation

user phone
user_phone
PK user_id PK phone_id
PK,FK1 phone_id
PK user_id
first_name country_code
last_name number
type
nickname extension
address
city
province
postal_code
country email
web_url
PK address
picture
notes
FK1 user_id
email_format
Second Normal Form
Table must be in First Normal Form •
Remove vertical redundancy •
The same value should not repeat across rows –
Composite keys •
All columns in a row must refer to BOTH parts –
of the key
Benefits •
Increased storage efficiency –
Less data repetition –
Satisfying 2NF

user user_phone phone


user
PK user_id PK,FK1 user_id PK phone_id
PK user_id PK,FK2 phone_id
first_name country_code
last_name
first_name number
nickname
last_name extension
address
nickname type
city
address
province
city
email postal_code
province user_company
email country
postal_code company
PK address web_url
country PK,FK1 user_id
PK address PK company_id
picture
web_url PK,FK2 company_id
type notes
picture
FK1 user_id name
FK1 user_id email_format
notes department
Third Normal Form
Table must be in Second Normal Form •
If your table is 2NF, there is a good chance it is –
3NF
All columns must relate directly to the •
primary key
Benefits •
No extraneous data –
Satisfying 3NF

user_phone
phone
user
PK,FK1 user_id
PK phone_id
PK user_id PK,FK2 phone_id
country_code
first_name extension
number
last_name
type
nickname
address
city
email province
postal_code user_company
PK address country company
PK,FK1 user_id
web_url
PK,FK2 company_id PK company_id
FK1 user_id picture
format notes
department name

Das könnte Ihnen auch gefallen