normalization exercises a337. 2 normalization example 1

16
Normalization Normalization Exercises Exercises A337

Upload: derrick-newman

Post on 31-Dec-2015

289 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: Normalization Exercises A337. 2 Normalization Example 1

Normalization ExercisesNormalization ExercisesA337

Page 2: Normalization Exercises A337. 2 Normalization Example 1

2

PACKID TAGNUM COMPID INSTDATE SOFTCOST EMPNUM EMPNAME LOCATIONAC01 32808 M579 9/13/95 754.95 611 Dinh, Melissa AccountingDB32 32808 M579 12/13/95 380.00 611 Dinh, Melissa Accounting

37691 B121 6/15/95 380.00 124 Alvarez, Ramon SalesDB33 57772 C007 5/27/95 412.77 567 Feinstein, Betty Info SystemsWP08 37691 B121 6/15/95 227.50 124 Alvarez, Ramon Sales

57772 C007 5/27/95 170.24 567 Feinstein, Betty Info SystemsWP09 59836 B221 10/30/95 35.00 124 Alvarez, Ramon Home

77740 M579 5/27/95 35.00 567 Feinstein, Betty Home

SOFTWARE

Normalization Example 1Normalization Example 1

Page 3: Normalization Exercises A337. 2 Normalization Example 1

3

1st Normal Form1st Normal Form

PACKID TAGNUMCOMPID INSTDATE SOFTCOST EMPNUM EMPNAME LOCATIONAC01 32808 M579 9/12/1991 754.95 611 Dinh, Melissa AccountingDB32 32808 M579 12/12/1991 380.00 611 Dinh, Melissa AccountingDB32 37691 B121 6/14/1991 380.00 124 Alvarez, Ramon SalesDB33 57772 C007 5/26/1991 412.77 567 Feinstein, Betty Info SystemsWP08 37691 B121 6/14/1991 227.50 124 Alvarez, Ramon SalesWP08 57772 C007 5/26/1991 170.24 567 Feinstein, Betty Info SystemsWP09 59836 B221 10/29/1991 35.00 124 Alvarez, Ramon HomeWP09 77740 M579 5/26/1991 35.00 567 Feinstein, Betty Home

SOFTWARE

Primary Key

Page 4: Normalization Exercises A337. 2 Normalization Example 1

22ndnd Normal Form Normal Form

PACKID TAGNUM

PACKID

TAGNUM

Create 3 TablesCreate 3 Tables

Distribute the remaining AttributesDistribute the remaining AttributesCOMPIDINSTDATESOFTCOSTEMPNUMEMPNAMELOCATION

Page 5: Normalization Exercises A337. 2 Normalization Example 1

22ndnd Normal Form Normal Form

PACKID TAGNUM

PACKID

TAGNUM

INSTDATE, SOFTCOST

(none in this example), could be things like package name, version, etc.

COMPID, EMPNUM, EMPNAME, LOCATION

Because the Package table has only one field (PACKID), we really don’t need this table

Page 6: Normalization Exercises A337. 2 Normalization Example 1
Page 7: Normalization Exercises A337. 2 Normalization Example 1

8

Normalization Example 2Normalization Example 2

SSN LAST_NAME FIRST_NAME PHONE_NO LIC_PLATE_ST LIC_PLATE_NO TICKET_NO DATE CODE FINE123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 10151 10/15/98 A 10$

10152 10/16/98 B 20$ 10121 11/12/98 B 20$

134-56-7783 Fong May (916)563-7865 CA 253 DAL 10231 10/23/98 C 50$ 12051 12/5/98 A 10$

PARKING TICKETS

Don’t be tricked!!! The first column of the data is not always the primary key of the 1NF table.

Page 8: Normalization Exercises A337. 2 Normalization Example 1

9

1st Normal Form1st Normal Form

TICKET_NO SSN LAST_NAME FIRST_NAME PHONE_NO LIC_PLATE_ST LIC_PLATE_NO DATE CODE FINE10151 123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 10/15/98 A 10$ 10152 123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 10/16/98 B 20$ 10121 123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 11/12/98 B 20$ 10231 134-56-7783 Fong May (916)563-7865 CA 253 DAL 10/23/98 C 50$ 12051 134-56-7783 Fong May (916)563-7865 CA 253 DAL 12/5/98 A 10$

Primary Key

PARKING TICKETS

If 1NF has only one column as the primary key (no composite key) then 1NF and 2NF are the SAME!!!!!

Page 9: Normalization Exercises A337. 2 Normalization Example 1

10

2nd Normal Form2nd Normal Form

TICKET_NO SSN LAST_NAME FIRST_NAME PHONE_NO LIC_PLATE_ST LIC_PLATE_NO DATE CODE FINE10151 123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 10/15/98 A 10$ 10152 123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 10/16/98 B 20$ 10121 123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD 11/12/98 B 20$ 10231 134-56-7783 Fong May (916)563-7865 CA 253 DAL 10/23/98 C 50$ 12051 134-56-7783 Fong May (916)563-7865 CA 253 DAL 12/5/98 A 10$

Primary Key

PARKING TICKETS

Page 10: Normalization Exercises A337. 2 Normalization Example 1

11

3rd Normal Form3rd Normal Form

TICKET_NO SSN DATE CODE10151 123-34-5678 10/15/98 A10152 123-34-5678 10/16/98 B10121 123-34-5678 11/12/98 B10231 134-56-7783 10/23/98 C12051 134-56-7783 12/5/98 A

PARKING TICKETS

REGISTRATIONSSN LAST_NAME FIRST_NAME PHONE_NO LIC_PLATE_ST LIC_PLATE_NO123-34-5678 Curry Dorothy (916)358-4448 CA 123 MCD134-56-7783 Fong May (916)563-7865 CA 253 DAL

FINESCODE FINE

A 10$ B 20$ C 50$

Knowing the nature of the information, we can see that one person can have two cars and probably LIC_PLATE_NO should be the primary key for the REGISTRATION table and the foreign key for the PARKING_TICKETS table and that another table with LIC_PLATE_NO and LIC_PLATE_ST as a primary key and SSN as a foreign key should exist

Page 11: Normalization Exercises A337. 2 Normalization Example 1

12

3rd Normal Form3rd Normal Form

TICKET_NOLIC_PLATE_NOLIC_PLATE_ST DATE CODE10151 123 MCD CA 10/15/1998 A10152 123 MCD CA 10/16/1998 B10121 123 MCD CA 11/12/1998 B10231 253 DAL CA 10/23/1998 C12051 253 DAL CA 12/5/1998 A

PARKING TICKETS

REGISTRATIONLIC_PLATE_NO LIC_PLATE_ST SSN

123 MCD CA 123-34-5678253 DAL CA 134-56-7783

FINESCODE FINE

A 10$ B 20$ C 50$

INDIVIDUALSSSN LAST_NAME FIRST_NAME PHONE_NO123-34-5678 Curry Dorothy (916)358-4448134-56-7783 Fong May (916)563-7865

Page 12: Normalization Exercises A337. 2 Normalization Example 1
Page 13: Normalization Exercises A337. 2 Normalization Example 1

14

Normalization Example 3Normalization Example 3I nvoiceI D CustomerI DCompanyName PhoneNumber Contact I nventoryI DQuantity UnitPrice

214123 30139 Cavco I ndustries I nc.(602) 555-6141Golkin, David 1207 10 $8.40

1191 15 $4.50

1101 10 $8.10

1143 1 $6.30

214390 30174 Thomas Nelson I nc. (615) 555-9079Harber, L. H. 1157 12 $9.30

1171 4 $7.40

1187 3 $22.00

1224 14 $15.20

1226 11 $12.90

214418 30174 Thomas Nelson I nc. (615) 555-9079Harber, L. H. 1250 1 $11.60

1175 8 $11.70

1114 10 $9.50

214460 30139 Cavco I ndustries I nc.(602) 555-6141Golkin, David 1141 9 $7.90

1136 3 $7.00

1143 1 $6.30

1149 20 $6.00

1207 3 $8.40

1104 16 $5.30

214480 30125 Alamo Group I nc. (210) 555-1483Maul, Duane A. 1207 20 $8.40

1143 1 $6.30

1136 18 $7.00

1250 4 $11.60

Page 14: Normalization Exercises A337. 2 Normalization Example 1

15

11stst Normal Form Normal FormInvoiceID InventoryID CustomerID CompanyName PhoneNumber Contact Quantity UnitPrice

214123 1207 30139Cavco Industries Inc. (602) 555-6141Golkin, David 10 $8.40214123 1191 30139Cavco Industries Inc. (602) 555-6141Golkin, David 15 $4.50214123 1101 30139Cavco Industries Inc. (602) 555-6141Golkin, David 10 $8.10214123 1143 30139Cavco Industries Inc. (602) 555-6141Golkin, David 1 $6.30214390 1157 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 12 $9.30214390 1171 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 4 $7.40214390 1187 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 3 $22.00214390 1224 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 14 $15.20214390 1226 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 11 $12.90214418 1250 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 1 $11.60214418 1175 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 8 $11.70214418 1114 30174Thomas Nelson Inc. (615) 555-9079Harber, L. H. 10 $9.50214460 1141 30139Cavco Industries Inc. (602) 555-6141Golkin, David 9 $7.90214460 1136 30139Cavco Industries Inc. (602) 555-6141Golkin, David 3 $7.00214460 1143 30139Cavco Industries Inc. (602) 555-6141Golkin, David 1 $6.30214460 1149 30139Cavco Industries Inc. (602) 555-6141Golkin, David 20 $6.00214460 1207 30139Cavco Industries Inc. (602) 555-6141Golkin, David 3 $8.40214460 1104 30139Cavco Industries Inc. (602) 555-6141Golkin, David 16 $5.30214480 1207 30125Alamo Group Inc. (210) 555-1483Maul, Duane A. 20 $8.40214480 1143 30125Alamo Group Inc. (210) 555-1483Maul, Duane A. 1 $6.30214480 1136 30125Alamo Group Inc. (210) 555-1483Maul, Duane A. 18 $7.00214480 1250 30125Alamo Group Inc. (210) 555-1483Maul, Duane A. 4 $11.60

Page 15: Normalization Exercises A337. 2 Normalization Example 1

16

22ndnd Normal Form Normal FormInvoiceID InventoryID Quantity

214123 1207 10214123 1191 15214123 1101 10214123 1143 1214390 1157 12214390 1171 4214390 1187 3214390 1224 14214390 1226 11214418 1250 1214418 1175 8214418 1114 10214460 1141 9214460 1136 3214460 1143 1214460 1149 20214460 1207 3214460 1104 16214480 1207 20214480 1143 1214480 1136 18214480 1250 4

InvoiceID CustomerID CompanyName PhoneNumber Contact214123 30139Cavco Industries Inc. (602) 555-6141 Golkin, David214390 30174Thomas Nelson Inc. (615) 555-9079 Harber, L. H.214418 30174Thomas Nelson Inc. (615) 555-9079 Harber, L. H.214460 30139Cavco Industries Inc. (602) 555-6141 Golkin, David214480 30125Alamo Group Inc. (210) 555-1483 Maul, Duane A.

InventoryID UnitPrice1101 $8.101104 $5.301114 $9.501136 $7.001141 $7.901143 $6.301149 $6.001157 $9.301171 $7.401175 $11.701187 $22.001191 $4.50

1207 $8.401224 $15.201226 $12.901250 $11.60

Page 16: Normalization Exercises A337. 2 Normalization Example 1

17

33rdrd Normal Form Normal FormInvoiceID InventoryID Quantity

214123 1207 10214123 1191 15214123 1101 10214123 1143 1214390 1157 12214390 1171 4214390 1187 3214390 1224 14214390 1226 11214418 1250 1214418 1175 8214418 1114 10214460 1141 9214460 1136 3214460 1143 1214460 1149 20214460 1207 3214460 1104 16214480 1207 20214480 1143 1214480 1136 18214480 1250 4

InventoryID UnitPrice1101 $8.101104 $5.301114 $9.501136 $7.001141 $7.901143 $6.301149 $6.001157 $9.301171 $7.401175 $11.701187 $22.001191 $4.50

1207 $8.401224 $15.201226 $12.901250 $11.60

InvoiceID CustomerID214123 30139214390 30174214418 30174214460 30139214480 30125

CustomerID CompanyName PhoneNumber Contact30125Alamo Group Inc. (210) 555-1483Maul, Duane A.30139Cavco Industries Inc. (602) 555-6141Golkin, David30174Thomas Nelson Inc. (615) 555-9079Harber, L. H.