Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITN 170 - Table Normalization1 ITN 170 MySQL Database Programming Lecture 3 :Database Analysis and Design (III) Normalization.

Similar presentations


Presentation on theme: "ITN 170 - Table Normalization1 ITN 170 MySQL Database Programming Lecture 3 :Database Analysis and Design (III) Normalization."— Presentation transcript:

1 ITN 170 - Table Normalization1 ITN 170 MySQL Database Programming Lecture 3 :Database Analysis and Design (III) Normalization

2 ITN 170 - Table Normalization2  Define normalization and explain its benefits.  Place tables in Third Normal Form.  Explain how conceptual data modeling rules ensure normalized tables. Section objectives

3 ITN 170 - Table Normalization3 Normalize Tables Categorize tables according to their degree of normalization. Normal Form RuleDescription First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) The table must be expressed as a set of unordered, two-dimensional tables. The table cannot contain repeating groups. The table must be in 1NF. Every non- key column must be dependent on all parts of the primary key. The table must be 2NF. No non-key column may be functionally dependent on another non-key column.

4 ITN 170 - Table Normalization4 Normalize Tables “Each non-primary key value MUST be dependent on the key, the whole key, and nothing but the key.” Why normalize tables?  Normalization minimizes data redundancy. Un-normalized data is redundant.  Data redundancy causes integrity problems. Update and delete transactions may not be consistently applied to all copies of the data causing inconsistencies in the data.  Normalization helps identify missing entities, relationships, and tables.

5 ITN 170 - Table Normalization5 Normalize Tables In addition to the three normal forms we mentioned, there are some more higher normal forms such as Boyce-Codd normal form, fourth normal form, and fifth normal form. However, they are not widely used in database designs. In general, third normal form is accepted goal for a database design that eliminates redundancy.

6 ITN 170 - Table Normalization6 This an Excel table. Looks nice, isn’t it?

7 ITN 170 - Table Normalization7 Why is this data un-normalized? Recognize Un-normalized Data Let’s simplify the Excel Table as follows: Consider the following set of data. The Excel Table is un-normalized. Un- normalized data does not comply with any of the rules of normalization we just mentioned. Three variable length records are shown – one for each ORDER_ID, i.e. 2301, 2302, and 2303. ORDER_IDDATECUST_IDCUST_NAMESTATEITEM NUM ITEM DESCRIP QUANTITYPRICE 23016/23101VolleyriteIL3786net335.00 4011racket665.00 91323-pack84.75 23026/25107Herman’sWI57946-pack45.00 23036/26110We-R-SportsMI4011racket265.00 3141cover210.00

8 ITN 170 - Table Normalization8 Recognize Un-normalized Data Remember, First Normal Form prohibits repeating groups. [Answer] The table contains a repeating group of ITEM NUM, ITEM DESCRIPTION, QUANTITY, and PRICE. ORDER_IDDATECUST_IDCUST_NAMESTATEITEM NUM ITEM DESCRIP QUANTITYPRICE 23016/23101VolleyriteIL3786net335.00 4011racket665.00 91323-pack84.75 23026/25107Herman’sWI57946-pack45.00 23036/26110We-R-SportsMI4011racket265.00 3141cover210.00

9 ITN 170 - Table Normalization9 First Normal Form Remove any repeating groups:  Fill the identical data in the empty spaces of the base table (temporarily makes the base table to be a non-repeated group)  Remove the repeating group from the base table  Create a new table with the PK column from the base table and the repeating group.

10 ITN 170 - Table Normalization10 Fill the identical data in the base table to temporarily avoid the repeating group in the base table, for a table with repeating groups is illegal for violating database definition. First Normal Form (continued) ORDER_IDDATECUST_IDCUST_NAMESTATEITEM NUM ITEM DESCRIP QUANTITYPRICE 23016/23101VolleyriteIL3786net335.00 4011racket665.00 91323-pack84.75 23026/25107Herman’sWI57946-pack45.00 23036/26110We-R-SportsMI4011racket265.00 3141cover210.00 23016/23101VolleyriteIL 23016/23101VolleyriteIL 23036/26110We-R-SportsMI

11 ITN 170 - Table Normalization11 Remove the repeating group of ITEM NUM, ITEM DESCRIPTION, QUANTITY, and PRICE from the following table to a new table. The PK of the remaining table is ORDER ID. Create a new ORDER_ITEM table with ORDER ID and the repeating group. First Normal Form (continued) ORDER_IDDATECUST_IDCUST_NAME STATE ITEM NUM ITEM DESCRIP QUANTITYPRICE 23016/23101VolleyriteIL3786net335.00 4011racket665.00 91323-pack84.75 23026/25107Herman’sWI57946-pack45.00 23036/26110We-R-SportsMI4011racket265.00 3141cover210.00 23016/23101VolleyriteIL 23016/23101VolleyriteIL 23036/26110We-R-SportsMI

12 ITN 170 - Table Normalization12 First Normal Form (continued) ORDER_ID DATE CUST_ID CUST_NAME STATE 23016/23101VolleyriteIL 23026/25107Herman’sWI 23036/26110We-R-SportsMI Therefore, we normalize the “Big” table into two “Small” relational tables (ORDER table and ORDER_ITEM table). ORDER_IDITEM NUMITEM DESCRIPQUANTITYPRICE 23013786net335.00 4011racket665.00 91323-pack84.75 230257946-pack45.00 23034011racket265.00 3141cover210.00 2301 2303 ORDER ORDER_ITEM

13 ITN 170 - Table Normalization13 Second Normal Form Remove any non-key columns that are not dependent upon the table’s entire primary key.  Determine which non-key columns are not dependent upon the table’s entire primary key.  Remove those columns from the base table.  Create second table with those columns and the columns(s) from the PK that they are dependent upon.

14 ITN 170 - Table Normalization14 Put the ORDER table in 2NF. ORDER_ID DATE CUST_ID CUST_NAME STATE 23016/23101VolleyriteIL 23026/25107Herman’sWI 23036/26110We-R-SportsMI Remember, for a Second Normal Form table. The table must be first in 1NF. Then, every non-key column must be dependent on all parts of the primary key. Is this in 2NF? Second Normal Form (continued)

15 ITN 170 - Table Normalization15  The ORDER table is already in 2NF. Any value of ORDER_ID uniquely determines a single value of each column. Therefore, all columns are dependent on the PK ORDER_ID. ORDER_ID DATE CUST_ID CUST_NAME STATE 23016/23101VolleyriteIL 23026/25107Herman’sWI 23036/26110We-R-SportsMI Second Normal Form (continued) [Answer]

16 ITN 170 - Table Normalization16 So, what about this? Remove any non-key columns that are not dependent upon the table’s entire primary key. Put the ORDER_ITEM table in 2NF. Still. Remember, for a Second Normal Form table. The table must be first in 1NF. Then, every non-key column must be dependent on all parts of the primary key. ORDER_IDITEM NUMITEM DESCRIPQUANTITYPRICE 23013786net335.00 4011racket665.00 91323-pack84.75 230257946-pack45.00 23034011racket265.00 3141cover210.00 2301 2303 Second Normal Form (continued)

17 ITN 170 - Table Normalization17  No. The ORDER_ITEM table is not in 2NF since PRICE and ITEM DESCRIPTION are dependent upon ITEM NUM, but not dependent upon ORDER ID. ORDER_IDQUANTITY 23013 6 8 23024 23032 ITEM NUM 3786 4011 9132 5794 4011 3141 2 ITEM DESCRIPPRICE net35.00 racket65.00 3-pack4.75 6-pack5.00 racket65.00 cover10.00 2301 2303 Now. How to convert to 2NF? Second Normal Form (continued) [Answer]

18 ITN 170 - Table Normalization18  To convert the table to 2NF, remove any partially dependent columns. Create an ITEM table with those columns and the column from part of PK columns that they are dependent upon. ORDER_IDQUANTITY 23013 6 8 23024 23032 ITEM NUM 3786 4011 9132 5794 4011 31412 2301 2303 ITEM ORDER_ITEM ITEM NUMITEM DESCRIPPRICE 3786net35.00 4011racket65.00 91323-pack4.75 57946-pack5.00 3141cover10.00 ??? Second Normal Form (continued)

19 ITN 170 - Table Normalization19 Remove any columns that are dependent upon another non-key column.  Determine which columns are dependent upon another non-key column.  Remove those columns from the base table.  Create a second table with those columns and the non-key column that they are dependent upon. Third Normal Form

20 ITN 170 - Table Normalization20 Is this in 3NF? ORDER table is already in 2NF as mentioned. Put the ORDER table in 3NF. Remember. Remove any columns that are dependent upon another non-key column ORDER_ID DATE CUST_ID CUST_NAME STATE 23016/23101VolleyriteIL 23026/25107Herman’sWI 23036/26110We-R-SportsMI Third Normal Form (continued)

21 ITN 170 - Table Normalization21 ORDER_ID DATE CUST_ID CUST_NAME STATE 23016/23101VolleyriteIL 23026/25107Herman’sWI 23036/26110We-R-SportsMI  CUSTOMER NAME and STATE are dependent upon CUSTOMER ID. Since you know that CUSTOMER ID is not the PK. Therefore, the ORDER table is not in 3NF. Third Normal Form (continued) [Answer]

22 ITN 170 - Table Normalization22 ORDER_ID DATE CUST_ID 23016/23101 23026/25107 23036/26110  Move the dependent non-key columns with the non-key column they depend upon into a new CUSTOMER table. CUST_ID CUST_NAME STATE 101VolleyriteIL 107Herman’sWI 110We-R-SportsMI ORDER CUSTOMER Note: A table is in Third Normal Form if no non-key column is functionally dependent upon another non- key column Third Normal Form (continued)

23 ITN 170 - Table Normalization23 Is this in 3NF? No non-key column can be functionally dependent upon another non-key column. Example Consider the ORDER_ITEM table as follows: ORDER_IDQUANTITY 23013 6 8 23024 23032 ITEM NUM 3786 4011 9132 5794 4011 31412 2301 2303 Third Normal Form (continued)

24 ITN 170 - Table Normalization24 Consider the ORDER_ITEM table as follows: ORDER_IDQUANTITY 23013 6 8 23024 23032 ITEM NUM 3786 4011 9132 5794 4011 31412 2301 2303  All non-key attributes are dependent on the key, the whole key, and nothing but the key. Therefore, the ORDER_ITEM table is in 3NF. [Answer] Third Normal Form (continued)

25 ITN 170 - Table Normalization25 What about this? No non-key column can be functionally dependent upon another non-key column. Example Consider the ITEM table as follows: ITEM NUMITEM DESCRIPPRICE 3786net35.00 4011racket65.00 91323-pack4.75 57946-pack5.00 3141cover10.00 Third Normal Form (continued)

26 ITN 170 - Table Normalization26 Consider the ITEM table as follows:  All non-key attributes are dependent on the key, the whole key, and nothing but the key. Therefore, the ITEM table is in 3NF. ITEM NUMITEM DESCRIPPRICE 3786net35.00 4011racket65.00 91323-pack4.75 57946-pack5.00 3141cover10.00 [Answer] Third Normal Form (continued)

27 ITN 170 - Table Normalization27 Ensure a 3NF table design by following the rules of data modeling.  A table must contain no repeating groups [First Normal Form Rule] Example CLIENT #* identifier * date contacted Is this entity CLIENT in 1NF? If not, how could it be converted to 1NF? Normalization During data Modeling

28 ITN 170 - Table Normalization28 CONTACT #* date contacted o location o result [Answer]  The attribute date contacted has multiple values, therefore the entity CLIENT is not in 1NF.  Create an additional entity CONTACT with a M:1 relationship to CLIENT. Create an additional entity and 1:M relationship to ensure 1NF. CLIENT #* identifier for the subject of Normalization During data Modeling

29 ITN 170 - Table Normalization29 Validate attribute dependence upon its entity’s entire UID.  Every non-key column must be dependent upon all parts of the primary key. [Second Normal Form Rule]  An attribute must be dependent upon it entity’s entire unique identifier. [Corresponding Data Modeling Rule] Normalization During data Modeling

30 ITN 170 - Table Normalization30 ACCOUNT #* number o balance o date opened o bank location BANK #* number * name managed by the manager of Are all of the attribute in the E-R diagram dependent upon their entity’s UID? Example Normalization During data Modeling

31 ITN 170 - Table Normalization31 [Answer]  The attribute bank location is not dependent upon the UID of ACCOUNT. It is dependent upon the UID of BANK.  Move the attribute and place it where it depends upon the UID of it’s entity. ACCOUNT #* number o balance o date opened BANK #* number * name o bank location managed by the manager of Normalization During data Modeling

32 ITN 170 - Table Normalization32 Validate attribute placement to ensure a normalized table design.  No non-key column can be functionally dependent upon another non-key column. [Third Normal Form Rule]  No non-UID attribute can be dependent upon another non-UID attribute. [Corresponding Data Modeling Rule] Normalization During data Modeling

33 ITN 170 - Table Normalization33 Example ORDER #* id * date of order * customer id * customer name * state Are any of the non-UID attributes for this entity dependent upon another non-UID attributes? Normalization During data Modeling

34 ITN 170 - Table Normalization34 ORDER #* id * date of order CUSTOMER #* id * name * state for the submitter of [Answer]  The attributes customer name and state are dependent upon the customer id.  Create another entity called CUSTOMER with a UID of customer id, and place the attributes accordingly. Normalization During data Modeling


Download ppt "ITN 170 - Table Normalization1 ITN 170 MySQL Database Programming Lecture 3 :Database Analysis and Design (III) Normalization."

Similar presentations


Ads by Google