32
NORMALIZACIÓN PROF. WANDA I NEGRON RIOS [email protected] COPYRIGHT © 2016

NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

NORMALIZACIÓNPROF. WANDA I NEGRON RIOS

[email protected]

COPYRIGHT © 2016

Page 2: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 3: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 4: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 5: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 6: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 7: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 8: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 9: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 10: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 11: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 12: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 13: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 14: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 15: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 16: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 17: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 18: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 19: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 20: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 21: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 22: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 23: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 24: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 25: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 26: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 27: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 28: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 29: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 30: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 31: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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

Page 32: NORMALIZACIÓNprofwnegron.weebly.com/uploads/8/1/9/1/8191586/... · let’s look at this table: order_ number order_ date delivery_ date part_ number part_ amount part_ description

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