Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL Normalization Database Design Lecture 5. Copyright 2006Page 2 SQL Normalization Database Design 1 st Normal Form 1 st Normal Form 2 nd Normal Form.

Similar presentations


Presentation on theme: "SQL Normalization Database Design Lecture 5. Copyright 2006Page 2 SQL Normalization Database Design 1 st Normal Form 1 st Normal Form 2 nd Normal Form."— Presentation transcript:

1 SQL Normalization Database Design Lecture 5

2 Copyright 2006Page 2 SQL Normalization Database Design 1 st Normal Form 1 st Normal Form 2 nd Normal Form 2 nd Normal Form 3 rd Normal Form 3 rd Normal Form Boyce-Codd Normal Form (BCNF) Boyce-Codd Normal Form (BCNF) 4 th Normal Form 4 th Normal Form 5 th Normal Form 5 th Normal Form 6 th Normal Form 6 th Normal Form Domain Key Normal Form (DKNF) Domain Key Normal Form (DKNF)

3 Copyright 2006Page 3 SQL Normalization Database Design: 1 st Normal Form 1 st Normal Form has 8 rules: 1 st Normal Form has 8 rules: Rows contain data for instances of an entity. Rows contain data for instances of an entity. Columns contain attributes that describe the data of an entity or its domain. Columns contain attributes that describe the data of an entity or its domain. Attributes in a given row, also known as a cell in spreadsheets, contain a single value. Attributes in a given row, also known as a cell in spreadsheets, contain a single value. All attributes define data by a single data type. All attributes define data by a single data type. All attributes have a unique name in an entity. All attributes have a unique name in an entity. Attributes are arbitrarily ordered. Attributes are arbitrarily ordered. Rows of data have no implicit or explicit ordering to access or use. Rows of data have no implicit or explicit ordering to access or use. Two rows may not contain duplicate data. Two rows may not contain duplicate data.

4 Copyright 2006Page 4 SQL Normalization Database Design: 1 st Normal Form 1 st Normal Form: 1 st Normal Form: Summary: A list of columns that (a) contain only an instance of a data type; and (b) define a collectively unique row. Summary: A list of columns that (a) contain only an instance of a data type; and (b) define a collectively unique row. Design Key #1: A single instance means that delimited values are not stored into a column, like a comma separated values (CSV) list. Design Key #1: A single instance means that delimited values are not stored into a column, like a comma separated values (CSV) list. Design Key #2: All columns taken together define a unique key that identifies a data structure. Design Key #2: All columns taken together define a unique key that identifies a data structure.

5 Copyright 2006Page 5 SQL Normalization Database Design: 2 nd Normal Form 2 nd Normal Form: 2 nd Normal Form: Summary: A row is in 2 nd normal form when the list of all non-key columns (or attributes) are fully dependent on the list of key columns, and the row meets the definition of 1 st normal form. Summary: A row is in 2 nd normal form when the list of all non-key columns (or attributes) are fully dependent on the list of key columns, and the row meets the definition of 1 st normal form. Design Key #1: The list of key columns defines the natural key that identifies a unique row. Design Key #1: The list of key columns defines the natural key that identifies a unique row. Design Key #2: A surrogate key (e.g., an automated numbering sequence) may replace the natural key. Design Key #2: A surrogate key (e.g., an automated numbering sequence) may replace the natural key.

6 Copyright 2006Page 6 SQL Normalization Database Design: 3 rd Normal Form 3 rd Normal Form: 3 rd Normal Form: Summary: A row is in 2 nd normal form when (a) there is no transitive dependency, which is a functional dependency; and (b) the row meets the definition of 2 nd normal form. Summary: A row is in 2 nd normal form when (a) there is no transitive dependency, which is a functional dependency; and (b) the row meets the definition of 2 nd normal form. Design Key #1: A functional dependency means that the domain is a super domain of two domains, and deleting a row from the base domain removes an instance from the functionally dependent domain. Design Key #1: A functional dependency means that the domain is a super domain of two domains, and deleting a row from the base domain removes an instance from the functionally dependent domain. Design Key #2: Functional dependencies can cause deletion anomalies. Design Key #2: Functional dependencies can cause deletion anomalies.

7 Copyright 2006Page 7 SQL Normalization Database Design: 3 rd Normal Form Functional Dependency: Functional Dependency: A 2 nd normal table exists when the domain contains both: A 2 nd normal table exists when the domain contains both: A RENTAL_ID that identifies two domains – the item rented and its rental price. A RENTAL_ID that identifies two domains – the item rented and its rental price. A deletion of RENTAL_ID 991 results in deleting the rental and the item rental price. A deletion of RENTAL_ID 991 results in deleting the rental and the item rental price. The ITEM_ID column is a functional dependency or transitive dependency. The ITEM_ID column is a functional dependency or transitive dependency. Create two 3 rd normal form tables by dividing the table into its separate domains. Create two 3 rd normal form tables by dividing the table into its separate domains. The ITEM_ID becomes the primary key in one table and foreign key in the other. The ITEM_ID becomes the primary key in one table and foreign key in the other. RENTAL_IDITEM_IDCHARGE 991 5-Day Rental 5 992 3-Day Rental 3 993 1-Day Rental 1 994 3-Day Rental 3 995 1-Day Rental 1

8 Copyright 2006Page 8 SQL Normalization Database Design: 3 rd Normal Form Functional Dependency Resolution: Functional Dependency Resolution: The ITEM_ID column becomes a primary key and unique description of any row in a 3 rd normal form table. The CHARGE column becomes wholly dependent on the new primary key. The RENTAL_ID column remains the primary key of a reduced domain and the ITEM_ID becomes a foreign key to the new 3 rd normal form table. The functional dependency of RENTAL_ID  CHARGE is eliminated. ITEM_IDCHARGE 5-Day Rental 5 3-Day Rental 3 1-Day Rental 1 RENTAL_IDITEM_ID 991 5-Day Rental 992 3-Day Rental 993 1-Day Rental 994 3-Day Rental 995 1-Day Rental

9 Copyright 2006Page 9 SQL Normalization Database Design: BCNF Boyce-Codd Normal Form (BCNF): Boyce-Codd Normal Form (BCNF): Summary: A row is in BCNF when (a) relations have a single determinant as a candidate key; and (b) the row meets the definition of 3 rd normal form. Summary: A row is in BCNF when (a) relations have a single determinant as a candidate key; and (b) the row meets the definition of 3 rd normal form. Design Key #1: A determinant lets you identify a row by combining it with one or more other columns to find a unique row in a relation, which is also known as a super key. Design Key #1: A determinant lets you identify a row by combining it with one or more other columns to find a unique row in a relation, which is also known as a super key. Design Key #2: A determinant is one or more attribute that does not qualify as a candidate key for a table but defines an internally or externally unique relation for a table. Design Key #2: A determinant is one or more attribute that does not qualify as a candidate key for a table but defines an internally or externally unique relation for a table.

10 Copyright 2006Page 10 SQL Normalization Database Design: BCNF Determinant Problem: Determinant Problem: A 3 rd normal table exists when the domain contains both: A 3 rd normal table exists when the domain contains both: A RENTAL_ID that identifies two domains – the item rented and its type – DVD or VHS. A RENTAL_ID that identifies two domains – the item rented and its type – DVD or VHS. A deletion of RENTAL_ID 991 results in deleting the rental and the VHS item TYPE of a TITLE. A deletion of RENTAL_ID 991 results in deleting the rental and the VHS item TYPE of a TITLE. The TYPE and TITLE column are only inserted when there is a RENTAL_ID, which means the type of rental cannot be inserted before it is rented. The TYPE and TITLE column are only inserted when there is a RENTAL_ID, which means the type of rental cannot be inserted before it is rented. Create two BCNF tables by dividing the table into its separate domains. Create two BCNF tables by dividing the table into its separate domains. RENTAL_IDTYPETITLE 991 VHSSTAR WARS IV 992 VHSSTAR WARS V 993 DVDSTAR WARS VI 994 DVDSTAR WARS IV 995 VHSSTAR WARS III

11 Copyright 2006Page 11 Summary 1 st Normal Form 1 st Normal Form 2 nd Normal Form 2 nd Normal Form 3 rd Normal Form 3 rd Normal Form Boyce-Codd Normal Form Boyce-Codd Normal Form 4 th Normal Form 4 th Normal Form 5 th Normal Form 5 th Normal Form 6 th Normal Form 6 th Normal Form Domain Key Normal Form (DKNF) Domain Key Normal Form (DKNF)


Download ppt "SQL Normalization Database Design Lecture 5. Copyright 2006Page 2 SQL Normalization Database Design 1 st Normal Form 1 st Normal Form 2 nd Normal Form."

Similar presentations


Ads by Google