normalizaciÓnprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table:...

Post on 03-Jun-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

NORMALIZACIÓNPROF. WANDA I NEGRON RIOS

WANDAI.NEGRON@UPR.EDU

COPYRIGHT © 2016

USER VIEWS

• A user view can help us see what data

is collected and saved by a system

• Examples of user views:

• Input / Output Screens

• A report

• A form

• A table

Prof. Wanda I. Negrón Rios - Copyright © 2016 2

USER VIEWS

• It’s just one of many places to start to

determine which data your system

needs to collect, process, and store

Prof. Wanda I. Negrón Rios - Copyright © 2016 3

LET’S LOOK AT THIS TABLE:

ORDER_

NUMBER

ORDER_

DATE

DELIVERY_

DATE

PART_

NUMBER

PART_

AMOUNT

PART_

DESCRIPTION

UNIT_

PRICE

VENDOR_

NUMBER

VENDOR_

NAME

VENDOR_

ADDRESS

11673 05/15/2013 05/29/2013 2396

1195

5893

3

4

1

Fan Belt

Oil Filter

Tail Lamp

$13.50

$5.75

$18.95

792

561

446

Acme

Harding

United

242 River St., Beacon, NY 10437

11 Oak Ave., Chadwick, NJ 07769

232 Hill Rd., Norwalk, CT 14876

11674 05/16/2013 05/30/2013 1195 1 Oil Filter $5.75 561 Harding 11 Oak Ave., Chadwick, NJ 07769

ORDER

Observe how for the first order, the first three fields would

have to be stored repeatedly for each part ordered.

This would mean repeating the same data three times.

This is inefficient use of data storage space.

Prof. Wanda I. Negrón Rios - Copyright © 2016 4

CONVERT TO THIS FORMAT:

ORDER_

NUMBER

ORDER_

DATE

DELIVERY_

DATE

PART_

NUMBER

PART_

AMOUNT

PART_

DESCRIPTION

UNIT_

PRICE

VENDOR_

NUMBER

VENDOR_

NAME

VENDOR_

ADDRESS

11673 05/15/2013 05/29/2013 2396

1195

5893

3

4

1

Fan Belt

Oil Filter

Tail Lamp

$13.50

$5.75

$18.95

792

561

446

Acme

Harding

United

242 River St., Beacon, NY 10437

11 Oak Ave., Chadwick, NJ 07769

232 Hill Rd., Norwalk, CT 14876

11674 05/16/2013 05/30/2013 1195 1 Oil Filter $5.75 561 Harding 11 Oak Ave., Chadwick, NJ 07769

ORDER

ORDER (Order_Number, Order_Date, Delivery_Date,

Part_Number, Part_Amount, Part_Description,

Unit_Price, Vendor_Number, Vendor_Name,

Vendor_Address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 5

UNDERLINE THE PRIMARY KEY

ORDER_

NUMBER

ORDER_

DATE

DELIVERY_

DATE

PART_

NUMBER

PART_

AMOUNT

PART_

DESCRIPTION

UNIT_

PRICE

VENDOR_

NUMBER

VENDOR_

NAME

VENDOR_

ADDRESS

11673 05/15/2013 05/29/2013 2396

1195

5893

3

4

1

Fan Belt

Oil Filter

Tail Lamp

$13.50

$5.75

$18.95

792

561

446

Acme

Harding

United

242 River St., Beacon, NY 10437

11 Oak Ave., Chadwick, NJ 07769

232 Hill Rd., Norwalk, CT 14876

11674 05/16/2013 05/30/2013 1195 1 Oil Filter $5.75 561 Harding 11 Oak Ave., Chadwick, NJ 07769

ORDER

ORDER (Order_Number, Order_Date, Delivery_Date,

Part_Number, Part_Amount, Part_Description,

Unit_Price, Vendor_Number, Vendor_Name,

Vendor_Address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 6

INDICATE REPEATING GROUPS { }

ORDER_

NUMBER

ORDER_

DATE

DELIVERY_

DATE

PART_

NUMBER

PART_

AMOUNT

PART_

DESCRIPTION

UNIT_

PRICE

VENDOR_

NUMBER

VENDOR_

NAME

VENDOR_

ADDRESS

11673 05/15/2013 05/29/2013 2396

1195

5893

3

4

1

Fan Belt

Oil Filter

Tail Lamp

$13.50

$5.75

$18.95

792

561

446

Acme

Harding

United

242 River St., Beacon, NY 10437

11 Oak Ave., Chadwick, NJ 07769

232 Hill Rd., Norwalk, CT 14876

11674 05/16/2013 05/30/2013 1195 1 Oil Filter $5.75 561 Harding 11 Oak Ave., Chadwick, NJ 07769

ORDER

ORDER (Order_Number, Order_Date, Delivery_Date,

{Part_Number, Part_Amount, Part_Description,

Unit_Price, Vendor_Number, Vendor_Name,

Vendor_Address})

Prof. Wanda I. Negrón Rios - Copyright © 2016 7

INDICATE REPEATING GROUPS { }

ORDER

(Order_number, Order_date, Delivery_date, {Part_number,

Part_amount, Part_description, Unit_price,Vendor_number,

Vendor_name, Vendor_address})

Prof. Wanda I. Negrón Rios - Copyright © 2016 8

FIRST NORMAL FORM (1NF)

1. Remove the repeating group and make it a table

You will end up with two tables

ORDER (Order_number, Order_date, Delivery_date)

(Part_number, Part_amount, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 9

FIRST NORMAL FORM (1NF)HOW DO WE “TIE” THE TWO TABLES?

1. Remove the repeating group and make it a table

ORDER (Order_number, Order_date, Delivery_date)

(Part_number, Part_amount, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Answer: adding the Primary Key of the first table

Prof. Wanda I. Negrón Rios - Copyright © 2016 10

FIRST NORMAL FORM (1NF)NOW YOUR TWO TABLES ARE CONNECTED

1. Remove the repeating group and make it a table

ORDER (Order_number, Order_date, Delivery_date)

(Order_number, Part_number, Part_amount,

Part_description, Unit_price, Vendor_number, Vendor_name,

Vendor_address)

** The second table has a compound or concatenated key.

Prof. Wanda I. Negrón Rios - Copyright © 2016 11

FIRST NORMAL FORM (1NF)NAME THE SECOND TABLE

1. Remove the repeating group and make it a table

ORDER (Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount,

Part_description, Unit_price, Vendor_number, Vendor_name,

Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 12

FIRST NORMAL FORM (1NF)COMPOUND PRIMARY KEY

ORDER (Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount,

Part_description, Unit_price, Vendor_number, Vendor_name,

Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 13

FIRST NORMAL FORM (1NF)

The new table (for the repeating group) will have:

• The Primary Key of the original table +

the fields from the repeating group

• The Primary Key will be a compound key* consisting of:

• The primary key of the original table +

the primary key of the repeating group

* Aka – Concatenated Key

Prof. Wanda I. Negrón Rios - Copyright © 2016 14

FIRST NORMAL FORM (1NF)

• WAIT…

• What if the table has no repeating groups?

(see example below)

• Then you will say:

• “The table is already in 1NF because there are no

repeating groups”

EMPLOYEE

(Employee_Number, Employee_Name, Employee_Address,

Employee_Education)

Prof. Wanda I. Negrón Rios - Copyright © 2016 15

SECOND NORMAL FORM (2NF)

• Remove Partial Dependencies

• This is applied to the table with the compound primary key

• All fields must be dependent on the primary key

(on the entire concatenated key)

• If you find fields that are only dependent on one part of

the compound key, take them out and make another table.

• Analyze each field

ORDER (Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 16

SECOND NORMAL FORM (2NF)

• Remove Partial Dependencies

• This is applied to the table with the compound primary key

• All fields must be dependent on the primary key

(on the entire concatenated key)

ORDER (Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount, Part_description,

Unit_price, Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 17

SECOND NORMAL FORM (2NF)

• Remove Partial Dependencies

ORDER

(Order_number, Order_date, Delivery_date)

“Order” is already in 2NF because it contains no

partial dependencies

Prof. Wanda I. Negrón Rios - Copyright © 2016 18

SECOND NORMAL FORM (2NF)

• Remove Partial Dependencies

• All fields must be dependent on the primary key

(on the entire concatenated key)

ORDER-PART

(Order_number, Part_number, Part_amount,

Part_description, Unit_price, Vendor_number,

Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 19

SECOND NORMAL FORM (2NF)

ORDER-PART

(Order_number, Part_number, Part_amount,

Part_description, Unit_price, Vendor_number,

Vendor_name, Vendor_address)

• Split this table into two tables:

• One table with the fields that depend on the

entire concatenated key

• Another with the fields that depend on only one

part of the concatenated keyProf. Wanda I. Negrón Rios - Copyright © 2016 20

SECOND NORMAL FORM (2NF)

ORDER-PART

(Order_number, Part_number, Part_amount)

PART

(Part_number, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Notice that the tables are connected through the

field Part_number.

Prof. Wanda I. Negrón Rios - Copyright © 2016 21

SECOND NORMAL FORM (2NF)ALL TABLES

ORDER

(Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount)

PART

(Part_number, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 22

THIRD NORMAL FORM (3NF)

• Remove Transitive Dependencies

• Where there is a non-key field that is dependent

on another (both non-keys)

• Check all tables for transitive dependencies

ORDER

(Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount)

PART

(Part_number, Part_description, Unit_price, Vendor_number,

Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 23

THIRD NORMAL FORM (3NF)

• Remove Transitive Dependencies

• Non-key field dependent on another non-key field

ORDER

(Order_number, Order_date, Delivery_date)

“Order” is already in 3NF because it contains no

transitive dependencies

Prof. Wanda I. Negrón Rios - Copyright © 2016 24

THIRD NORMAL FORM (3NF)

• Remove Transitive Dependencies

• Non-key field dependent on another non-key field

ORDER-PART

(Order_number, Part_number, Part_amount)

“Order-Part” is already in 3NF because it contains

no transitive dependencies

Prof. Wanda I. Negrón Rios - Copyright © 2016 25

THIRD NORMAL FORM (3NF)

• Remove Transitive Dependencies

• Non-key field dependent on another non-key field

PART

(Part_number, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 26

THIRD NORMAL FORM (3NF)

• Remove Transitive Dependencies

• Non-key field dependent on another non-key field

PART

(Part_number, Part_description, Unit_price,

Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 27

THIRD NORMAL FORM (3NF)

PART

(Part_number, Part_description, Unit_price,

Vendor_number)

VENDOR

(Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 28

THIRD NORMAL FORM (3NF)

• Remove Transitive Dependencies

• Create a new table with the fields from the 2NF

table that depend on another nonkey field

• The primary key of this table will be the field

that the other(s) depend on

• Leave the primary key of the new table in the

original table

• It will be called a foreign key – identified by a

dashed underline

Prof. Wanda I. Negrón Rios - Copyright © 2016 29

THIRD NORMAL FORM (3NF)LIST ALL YOUR TABLES

FINAL SOLUTIONORDER

(Order_number, Order_date, Delivery_date)

ORDER-PART

(Order_number, Part_number, Part_amount)

PART

(Part_number, Part_description, Unit_price, Vendor_number)

VENDOR

(Vendor_number, Vendor_name, Vendor_address)

Prof. Wanda I. Negrón Rios - Copyright © 2016 30

NOW WE PREPARE THE ERDS

• An Order contains one or many parts.

• A Part has only one description and unit price.

• A Part has only Vendor.

Prof. Wanda I. Negrón Rios - Copyright © 2016 31

Prof. Wanda I. Negrón Rios - Copyright © 2016 32

NOW WE PREPARE THE ERDS

VENDOR

PART

ORDER

ORDER-PART

conta

ins

has

Are

pa

rt o

f

Belongs to

sup

plie

s

Is s

upp

lied

by

top related