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 nickname phone1 phone2 phone3 cell pager address city province postal_code country email1 email2 web_url company department picture notes email_format

name
Mike Hillyer Tom Jensen Ray Smith

phone1
403-5551717 403-5551919 403-5551919

phone2
403-5551919

email1
mike@hoppen.c om

email2
mhillyer@mysite. com tom@supersite.or g

403-555- tom@openwin.or 1313 g 403-5551111 ray@cpma.com

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_name last_name nickname phone cell pager address city province postal_code country web_url department picture notes

first_na last_nam Mike Hillyer me e
Mike Tom Tom Ray Ray Hillyer Jensen Jensen Smith Smith

phone
403-5551717 403-5551919 403-5551919 403-5551313 403-5551919 403-5551111

email
mike@hoppen.com mhillyer@mysite.com tom@openwin.org tom@supersite.org ray@cpma.com

• • •

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 nickname address city province postal_code country web_url company department picture notes

email PK email_id address

phone PK phone_id country_code number extension

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 PK user_id first_name last_name nickname address city province postal_code country web_url picture notes email_format user_phone PK,FK1 phone_id PK user_id type PK phone phone_id country_code number extension

email PK FK1 address user_id

Our User Table
first_na last_nam company Mike Hillyer MySQL me e
Tom Ray Jensen Smith CPNS CPNS

department
Documentation Finance Documentation

user PK user_id first_name last_name nickname address city province postal_code country web_url picture notes email_format

user_phone PK,FK1 phone_id PK user_id type PK

phone phone_id country_code number extension

email PK FK1 address user_id

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 PK user_id PK user_id first_name last_name first_name nickname last_name address nickname city address province city postal_code province country postal_code web_url country picture web_url notes picture email_format notes user_phone PK,FK1 user_id PK,FK2 phone_id PK phone phone_id country_code number extension type

email email PK address PK address type FK1 user_id FK1 user_id

user_company PK,FK1 user_id PK,FK2 company_id department PK

company company_id name

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 user PK user_id first_name last_name nickname address city province postal_code country web_url picture notes PK,FK1 user_id PK,FK2 phone_id extension PK phone phone_id country_code number type

email PK FK1 address user_id format

user_company PK,FK1 user_id PK,FK2 company_id department company PK company_id name

Sign up to vote on this title
UsefulNot useful