1 / 44

Relational Database Design

Relational Database Design. Relational Database Design. Each relation schema consists of a number of attributes Database schema consists of a number of such relation schemas Relational database design ultimately produces a set of relations

deo
Download Presentation

Relational Database Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Relational Database Design

  2. Relational Database Design • Each relation schema consists of a number of attributes • Database schema consists of a number of such relation schemas • Relational database design ultimately produces a set of relations • How one grouping of attributes into a relation schema is better than another • Relational Database Design • store information without unnecessary redundancy • allows us to retrieve information easily

  3. Relational Database Design • Two Design methodologies • Top down (design by analysis) • starts with a number of groupings of attributes into relations that exist together naturally eg. Departmental store bill • Bottom up (design by synthesis) • basic relationships among individual attributes is the starting point and uses these to construct relation schemas • collect a large number of binary relationships among attributes - impossible, and not practical • Informal design guidelines • Designing schemas that are in an appropriate normal form • information about the real-world enterprise • Some of this information exists in a well-designed E-R diagram

  4. Informal design guidelines • Measures to determine the quality of relation schema design: • Making sure that the semantics of the attributes is clear in the schema • Reducing the redundant information in tuples • Reducing the NULL values in tuples • Disallowing the possibility of generating spurious tuples

  5. 1. Imparting Clear Semantics to Attributes in Relations • meaning resulting from the interpretation of attribute values in a tuple • Attributes belonging to one relation have certain real-world meaning and a proper interpretation associated with them • The ease with which the meaning of a relation’s attributes can be explained is an informal measure of how well the relation is designed.

  6. Imparting Clear Semantics to Attributes in Relations • Guideline 1 • Design a relation schema that is easy to explain its meaning. Do not combine attributes from multiple entity types and relationship types into a single relation

  7. Violates Guideline 1 EMP_DEPT mixes attributes of employees and departments, and EMP_PROJ mixes attributes of employees and projects and the WORKS_ON relationship. Hence, they fare poorly against the measure of design quality.

  8. 2. Redundant Information in Tuplesand Update Anomalies

  9. Insertion Anomalies • To insert a new employee tuple into EMP_DEPT, we must include either the attribute values for the department that the employee works for, or NULLs (if the employee does not work for a department as yet). • To insert a new tuple for an employee who works in department number 5, enter all the attribute values of department 5 correctly so that they are consistent with the corresponding values for department 5 in other tuples in EMP_DEPT. • It is difficult to insert a new department that has no employees in the EMP_DEPT relation • place NULL values in the attributes for employee. This violates the entity integrity for EMP_DEPT because Ssn is its primary key

  10. Deletion Anomalies If we delete from EMP_DEPT an employee tuple that happens to represent the last employee working for a particular department, the information concerning that department is lost from the database

  11. Modification Anomalies In EMP_DEPT, if we change the value of one of the attributes of a particular department—say, the manager of department 5—we must update the tuples of all employees who work in that department; otherwise, the database will become inconsistent.

  12. 2. Redundant Information in Tuples • Guideline 2 • Design the base relation schemas so that no insertion, deletion, or modification anomalies are present in the relations

  13. 3. NULL Values in Tuples • The attribute does not apply to this tuple. • For example, Visa_status may not apply to U.S. students. • The attribute value for this tuple is unknown. For example, the Date_of_birth may be unknown for an employee. • The value is known but absent; that is, it has not been recorded yet. • For example, the Home_Phone_Number for an employee may exist, but may not be available and recorded yet. • NULLs can waste space at the storage level and may also lead to problems with understanding the meaning of the attributes and with specifying JOIN operations at the logical level • Another problem with NULLs is how to account for them when aggregate operations such as COUNT or SUM are applied

  14. NULL Values in Tuples Guideline 3 As far as possible, avoid placing attributes in a base relation whose values may frequently be NULL. If NULLs are unavoidable, make sure that they apply in exceptional cases only and do not apply to a majority of tuples in the relation

  15. 4. Generation of Spurious Tuples

  16. EMP_PROJ – Removing redundancy

  17. 4. Generation of Spurious Tuples Additional tuples that were not in EMP_PROJ are called spurious tuples

  18. Generation of Spurious Tuples Design relation schemas so that they can be joined with equality conditions on attributes that are appropriately related (primary key, foreign key) pairs in a way that guarantees that no spurious tuples are generated Plocation is neither a primary key nor a foreign key in either EMP_LOCS or EMP_PROJ1

  19. Normalization • Takes a relation schema • Run through a series of tests to certify whether it satisfies a certain normal form. • To normalize them, decompose the relations

  20. First Normal Form • domain of an attribute must include only atomic (simple, indivisible) values and value of any attribute in a tuple must be a single value from the domain of that attribute • Disallows multivalued attributes, composite attributes, and their combinations • Example • Dlocationsis not an atomic attribute

  21. Decomposing Department relation

  22. Solutions • 1) Remove the attribute Dlocations that violates 1NF and place it in a separate relation DEPT_LOCATIONS along with the primary key Dnumber of DEPARTMENT. The primary key of this relation is the combination { Dnumber, Dlocation } • 2) Expand the key so that there will be a separate tuple in the original DEPARTMENT relation for each location of a DEPARTMENT (refer prev slide) • 3) If a maximum number of values is known for the attribute - at most three locations • replace the Dlocations attribute by three atomic attributes: Dlocation1, location2, and Dlocation3

  23. 1 NF

  24. 1 NF

  25. 2 NF A functional dependency, denoted by X → Y, between two sets of attributes X and Y that are subsets of R specifies a constraint on the possible tuples that can form a relation state r of R. The constraint is that, for any two tuplest1 and t2 in r that have t1 [X] = t2 [X], they must also have t1 [Y] = t2 [Y].

  26. Functional Dependency • EMP_PROJ • Ssn → Ename • the value of an employee’s Social Security number (Ssn) uniquely determines the employee name (Ename) • Pnumber → {Pname, Plocation} • value of a project’s number (Pnumber) uniquely determines the project name (Pname) and location (Plocation) • {Ssn, Pnumber} → Hours • combination of Ssn and Pnumber values uniquely determines the number of hours the employee currently works on the project per week (Hours)

  27. Second Normal Form • Based on the concept of full functional dependency • A functional dependency X → Y is a full functional dependency if removal of any attribute A from X means that the dependency does not hold any more • A functional dependency X→Y is a partial dependency if some attribute A ε X can be removed from X and the dependency still holds; that is, for some A ε X, (X – {A}) → Y. • { Ssn, Pnumber } → Hours is full fd • neither Ssn → Hours nor Pnumber → Hours holds • the dependency { Ssn, Pnumber }→Ename is partial because Ssn→Ename holds.

  28. Second Normal Form • An attribute of relation schema R is called a prime attribute of R if it is a member of some candidate key of R. • An attribute is called nonprime if it is not a prime attribute—that is, if it is not a member of any candidate key • Example • Both Ssn and Pnumber are prime attributes of WORKS_ON, whereas other attributes of WORKS_ON are nonprime.

  29. Second Normal Form A relation schema R is in 2NF if every nonprime attribute A in R is fully functionally dependent on the primary key of R.

  30. Decomposing into 2NF

  31. Third Normal form • based on the concept of transitive dependency • A functional dependency X→Y in a relation schema R is a transitive dependency if there exists a set of attributes Z in R that is neither a candidate key nor a subset of any key of R, and both X→Z and Z→Y hold. • Ssn→Dmgr_ssn is transitive • Ssn → Dnumber and Dnumber → Dmgr_ssnholds and Dnumber is neither a key itself nor a subset of the key of EMP_DEPT.

  32. Third Normal form a relation schema R is in 3NF if it satisfies 2NF and no nonprime attribute of R is transitively dependent on the primary key.

  33. 3NF General definition A relation schema R is in third normal form (3NF) if, whenever a nontrivial functional dependency X→A holds in R, either (a) X is a superkeyof R, or (b) A is a prime attribute of R.

  34. Summary of Normal Forms Based on Primary Keys

  35. Boyce-Codd Normal Form stricter than 3NF. That is, every relation in BCNF is also in 3NF A relation schema R is in BCNF if whenever a nontrivial functional dependency X→A holds in R, then X is a superkey of R.

  36. BCNF {Student, Course} is a candidate key FD1 : {Student, Course} → Instructor FD2: Instructor → Course decomposed into one of the three following possible pairs: {Student, Instructor} and {Student, Course} 2. {Course, Instructor} and {Course, Student} 3. {Instructor, Course} and {Instructor, Student}. All three decompositions lose the functional dependency FD1. Desirable is 3.

  37. Properties of decompositions • nonadditive join or lossless join property • spurious tuple generation problem does not occur with respect to the relation schemas created after decomposition • dependency preservation property • each functional dependency is represented in some individual relation resulting after decomposition • The nonadditive join property is extremely critical and must be achieved at any cost, whereas the dependency preservation property, although desirable, is sometimes sacrificed

  38. Functional dependency theory • The closure of F, denoted by F+, is the set of all functional dependencies logically implied by F • Axioms, or rules of inference, provide a simpler technique for reasoning about functional dependencies • Armstrong’s axioms

  39. Functional dependency theory • Armstrong’s axioms are sound, because they do not generate any incorrect functional dependencies and complete, because, for a given set F of functional dependencies, they allow us to generate all F+.

  40. Functional dependency theory schema R = (A, B, C, G, H, I) set F of functional dependencies {A→ B, A→ C, CG → H, CG → I , B → H}. Closure A → H. (A → B and B → H hold, apply transitivity) CG → HI. (Since CG → H and CG → I , the union rule implies that CG →HI ) AG → I. (Since A→C and CG → I , the pseudotransitivity rule implies that AG → I holds)

  41. Functional dependency theory

  42. Functional dependency theory (AG)+ result = AG

  43. Functional dependency theory several uses of the attribute closure algorithm

More Related