Relational Database Examples


Published on

An Example of a relational database and Normalisation

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Relational Database Examples

  1. 1. Relational Database Exercises John Cutajar
  2. 2. First Normal Form Which rule does this table violate? Change the following table in 1NF Databases 2
  3. 3. First Normal Form No repeating groups. As an example, it might be tempting to make an invoice table with columns for the first, second, and third line item (see above). 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), and *horrible* SQL statements with a separate join for each repetition of the column. First form normalization requires you make a separate line item table, with its own key (in this case the combination of invoice number and line number) Databases 3
  4. 4. From 1NF to 2NF Why not in 2NF: Now convert to 2NF Databases 4
  5. 5. Second Normal Form Each column must depend on the *entire* primary key. As an example, the customer information could be put in the line item table (previous slide). The trouble with that is that the customer goes with the invoice, not with each line on the invoice. Putting customer information in the line item table will cause redundant data, with its inherant overhead and difficult modifications. Second form normalization requires you place the customer information in the invoice table. Databases 5
  6. 6. From 2NF to 3NF Why not in 3NF: Now convert to 3NF Databases 6
  7. 7. Third Normal Form Each column must depend on *directly* on the primary key. As an example, the customer address could go in the invoice table (previous slide), but this would cause data redundancy if several invoices were for the same customer. It would also cause an update nightmare when the customer changes his address, and would require extensive programming to insert the address every time an existing customer gets a new invoice. Third form normalization requires the customer address go in a separate customer table with its own key (customer), with only the customer identifier in the invoice table. Databases 7
  8. 8. From 2NF to 3NF Now in 3NF Databases 8
  9. 9. First Normal Form Which rule does Members List this table violate? 1 John Cutajar Access, DB2, FoxPro Change the 2 Paul Borg dBase, Clipper following table in 3 Mary Hanks 1NF 4 Joe Doe DB2, Oracle 5 Tim Rice Oracle, Sybase 6 Paul Simon Informix 7 Ned Blue 8 Sam Red Access, MySQL 9 Tina Skoss Databases 9
  10. 10. From 1NF to 2NF Now to 2NF Database Table MID DID Database Members Table 1 1 Access MID Member 1 2 DB2 1 John Cutajar 1 3 FoxPro 2 Paul Borg 2 4 dBase 3 Mary Hanks 2 5 Clipper 4 Joe Doe 4 2 DB2 4 6 Oracle 5 Tim Rice 5 6 Oracle 6 Paul Simon 5 7 Sybase 7 Ned Blue 6 8 Informix 8 Sam Red 8 1 Access 9 Tina Skoss 8 2 MySQL Databases 10
  11. 11. From 2NF to 3NF Now in 3NF Database Table Members Table MID DID Database Table MID Member 1 1 DID Database 1 John Cutajar 1 2 1 Access 2 Paul Borg 1 3 2 DB2 3 Mary Hanks 2 4 3 FoxPro 4 Joe Doe 2 5 4 dBase 5 Tim Rice 4 2 5 Clipper 6 Paul Simon 4 6 6 Oracle 5 6 7 Sybase 7 Ned Blue 5 7 8 Informix 8 Sam Red 6 8 9 MySQL 9 Tina Skoss 8 1 8 9 Databases 11