Académique Documents
Professionnel Documents
Culture Documents
Chapter 11
Relational Database Design Algorithms and Further Dependencies
CS 6360.501 (Fall 2009) Instructor: Sunan Han
Outline
1. Properties of Relational Decompositions 2. Algorithms for Relational Database Schema
Algorithm 11.1: Testing for Non-additive Join Property Algorithm 11.2: Relational Synthesis into 3NF with Dependency Preservation Algorithm 11.3: Relational Decomposition into BCNF with non-additive join property Algorithm 11.4: Relational Synthesis into 3NF with Dependency Preservation and Non-Additive Join Property Algorithm 11.4a: Finding a Key K for R Given a set F of Functional Dependencies
Slide 11- 2
Relational Decompositions
Definition of Universal Relation Schema: A relation schema R = {A1, A2, , An} that includes all the attributes of the database. Universal relation assumption: Every attribute name is unique Think of this as a bottom-up design: we know all the attributes and functional dependencies in the database as a single relation. We need to find a way to decompose it into smaller relations that are in a desired normal form, as well as maintaining certain important properties
Slide 11- 3
Relational Decompositions
Decomposition:
The process of decomposing the universal relation schema R into a set of relation schemas D = {R1,R2, , Rm} that will become the relational database schema by using the functional dependencies.
A natural join will generate spurious tuples (e.g. Wong would work on project 30 in the join, which he was not supposed to)
Slide 11- 6
Definition of Projection
Given a set of dependencies F on R, the projection of F on Ri, denoted by Ri(F) where Ri is a subset of R, is the set of dependencies X Y in F+ such that the attributes in X Y are all contained in Ri (example on next slide) Hence, the projection of F on each relation schema Ri in the decomposition D = {R1,R2, , Rm} is the set of functional dependencies in F+, the closure of F, such that all their left- and right-hand-side attributes are in Ri. Informally, we want each dependency in R to be directly from one of the decomposed Ri or can be inferred from dependencies in some Ri. This is the dependency preservation condition
Slide 11- 7
For subset relation R1(Dnumber, Dname, Dmgr_ssn), the projection of F on R1 is the subset of FDs in F+ such that left and right hand side attributes of the FDs are in R1. So,
R1(F) = { Dnumber {Dname, Dmgr_ssn}, Dnumber Dname, Dnumber Dmgr_ssn }
Slide 10- 8
If a decomposition is not dependency-preserving, then some dependencies are lost in the decomposition
Slide 11- 9 Slide 11- 10
Slide 11- 11
Slide 11- 12
Slide 11- 13
Slide 11- 14
Slide 11- 17
Slide 11- 18
FD1
Slide 11- 19
Slide 10- 20
Slide 11- 22
Algorithm 11.3: Relational Decomposition into BCNF with non-additive join property
Input: A universal relation R and a set of functional dependencies F on the attributes of R.
1. Set D := {R}; 2. While there is a relation schema Q in D that is not in BCNF do { choose a relation schema Q in D that is not in BCNF; find a functional dependency X Y in Q that violates BCNF; replace Q in D by two relation schemas (Q - Y) and (X Y); }; Assumption: No null values are allowed for the join attributes.
Slide 11- 24
Algorithm 11.4: Relational Synthesis into 3NF with Dependency Preservation and NonAdditive Join Property
Input: A universal relation R and a set of functional dependencies F on the attributes of R.
1. Find a minimal cover G for F (Use Algorithm 10.2). 2. For each left-hand-side X of a functional dependency that appears in G, create a relation schema in D with attributes {X {A1} {A2} ... {Ak}}, where X A1, X A2, ..., X >Ak are the only dependencies in G with X as left-hand-side (X is the key of this relation). 3. If none of the relation schemas in D contains a key of R, then create one more relation schema in D that contains attributes that form a key of R. (Use Algorithm 11.4a to find the key of R) 4. Among decomposed relation schemas, if Ri is a subset of Rj, remove Ri
Slide 11- 25
Compute (K - A)+ with respect to F; If (K - A)+ contains all the attributes in R, (All attributes in R can be FDed by K-A) then set K := K - {A}; }
Slide 11- 26
Slide 11- 28
Slide 11- 31
Slide 11- 32
Summary of Algorithms
Slide 11- 33
Slide 11- 34
Chapter Summary
Designing a Set of Relations from decompositions Properties of Relational Decompositions Algorithms for Relational Database Schema
Assignment #9
Page 409, 11.27 (on 10.29 only), 11.29 (a), 11.30 (LJ1 = NJB on slide 19) Due date 11/9/09 (Monday)
Slide 11- 35
Slide 10- 36
Project Phase 3
1.
Project Phase 3
6.
2.
3. 4.
5.
Simplify the original model by removing the computer requirement (and therefore the administrator/administer relations) and by removing the accounting group/department. Normalize all of your tables to third normal form, if necessary. If a change is made, explain why. Draw a functional dependency diagram for each table schema Create the database and tables on MS SQL Server. Primary keys and foreign keys must be defined appropriately. Populate your tables with an initial state. Make sure all constraints (key, entity integrity, referential integrity and domain) are maintained and the initial state forms a real world database so that reasonable queries will return sensible results
7.
Use the Create View statement to create the following views: a. Employee: This view returns Employee_ID, First Name, Last Name, Rank, Supervisor ID, Address and Title of the employee. b. Senior employee: This view returns the Employee_ID, First Name, Last Name, and Salary of the employees whose Rank is above 6 including 6. c. Marketing information: This view returns the Employee_ID, Name of employee who is in the marketing group and the marketing sites and products the employee is in charge of. Make the following queries into your database. a. List the number of employees in the IT group. b. List the all the employees with the same title Sales Manager
Slide 11- 38
Slide 11- 37
Project Phase 3
7.
Project Phase 3
Submission
1. 2.
d.
e.
f.
g. h.
i.
j.
List the Last Name, Employee_ID, Rank, and Title of the female employees whose Rank is above 6 including 6. For a certain employee, find all his/her supervisees Last Name, Employee_ID, and Rank For a certain city (e.g. Richardson), find Employee_ID of all employees who live in that city. For a certain employee, find all the trips he/she made to a certain destination (like Atlanta). Find all the marketing sites which have at least 5 employees. List Name and Employee_ID of the employees who sold products at a certain marketing site. List all the VPs who are in charge of the Marketing Department and whose number of stocks is more than 10,000. Find all the product names sold by a particular marketing employee
Slide 11- 39
3. 4. 5.
6. 7.
The new simplified EER diagram. Relational model schema after simplification and normalization. Make sure all relations are in 3NF. The relation schemas should include primary keys as well as foreign keys and include arrowed lines from foreign keys to primary keys, for all relations. Dependency diagram for each table All requested SQL definition and view statements in 4, 5 and 6 All queries in 7. You are also required to demonstrate the 10 queries to my TA. Make appointment with Ling for 10 minutes per student, starting right after the due date The weight of Phase 3 is 50% of total project Due date 11/30/09 (Monday, right after the Thanksgiving break)
Slide 11- 40