
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































Normalization: Database Design Theory – Introduction to Normalization using Functional and Multivalued Dependencies: Informal design guidelines for relation schema, Functional Dependencies, Normal Forms based on Primary Keys, Second and Third Normal Forms, Boyce-Codd Normal Form, Multivalued Dependency and Fourth Normal Form, Join Dependencies and Fifth Normal Form. Normalization Algorithms: Inference Rules, Equivalence, and Minimal Cover, Properties of Relational Decompositions, Algorithms for Relational Database Schema Design, Nulls, Dangling tuples, and alternate Relational Designs, Further discussion of Multivalued dependencies and 4NF, Other dependencies and Normal Forms.
Four informal guidelines that may be used as 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
The group of attributes belonging to one relation have certain real-world meaning and a proper interpretation associated with them. The semantics of a relation refers to its meaning resulting from the interpretation of attribute values in a tuple.
If the conceptual design done carefully and the mapping procedure is followed systematically, the relational schema design should have a clear meaning. The meaning of the EMPLOYEE relation schema is quite simple: Each tuple represents an employee, with values for the employee’s name (Ename), Social Security number (Ssn), birth date (Bdate), and address (Address), and the number of the department that the employee works for (Dnumber).
Design a relation schema so that it is easy to explain its meaning.
Do not combine attributes from multiple entity types and relationship types into a single relation. If a relation schema corresponds to one entity type or one relationship type, it is straightforward to interpret and to explain its meaning. Otherwise, if the relation corresponds to a mixture of multiple entities and relationships, semantic ambiguities will result and the relation cannot be easily explained.
The following relation schema EMP_DEPT and EMP_PROJ have clear semantics but they violate Guideline 1 by mixing attributes from distinct real-world entities: 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 above measure of design quality.
Insertion anomalies can be differentiated into two types, based on the EMP_DEPT relation:
The problem of deletion anomalies is related to the second insertion anomaly situation.
Design the base relation schemas so that no insertion, deletion, or modification anomalies are present in the relations. If any anomalies are present, note them clearly and make sure that the programs that update the database will operate correctly.
1.3 NULL Values in Tuples
If many of the attributes do not apply to all tuples in the relation, we end up with many NULLs in those tuples. This can waste space at the storage level and may also lead to problems with understanding the meaning of the attributes. SELECT and JOIN operations involve comparisons; if NULL values are present, the results may become unpredictable. NULLs can have multiple interpretations, such as the following:
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.
1.4 Generation of Spurious Tuples
Consider the two relation schemas EMP_LOCS and EMP_PROJ1. Suppose if we perform
A functional dependency , denoted by X → Y means that the values of the Y are determined by the values of X . A functional dependency is a property of the semantics or meaning of the attributes. The database designers will use their understanding of the semantics of the attributes of R to specify the functional dependencies in a relation. Consider the relation schema EMP_PROJ from the semantics of the attributes and the relation, the following functional dependencies should hold: a. Ssn→Ename b. Pnumber →{Pname, Plocation} c. {Ssn, Pnumber}→Hours
These functional dependencies specifies that (a) the value of an employee’s Social Security number (Ssn) uniquely determines the employee name (Ename), (b) the value of a project’s number (Pnumber) uniquely determines the project name (Pname) and location (Plocation), and (c) Combination of Ssn and Pnumber values uniquely determines the number of hours the employee currently works on the project per week (Hours). Types of functional dependency :
3 Normal Forms Based on Primary Keys
3.1 Normalization of Relations The normalization process, as first proposed by Codd (1972). Codd proposed three normal forms, which he called first, second, third normal form and Boyce-Codd normal form (BCNF). All these normal forms are based on functional dependencies among the attributes of a relation. Later, a fourth normal form (4NF) and a fifth normal form (5NF) were proposed, based on the concepts of multivalued dependencies and join dependencies, respectively; Normalization of data can be considered a process of analyzing the given relation schemas based on their FDs and primary keys to achieve the desirable properties of (1) minimizing redundancy and (2) minimizing the insertion, deletion, and update anomalies. It can be considered as a “filtering” or “purification” process to make the design have successively better quality. Definition. The normal form of a relation refers to the highest normal form condition that it meets, and hence indicates the degree to which it has been normalized.
3.2 Definitions of Keys and Attributes Participating in Keys.
Definition. A superkey of a relation schema R is a set of attributes S ⊆ R with the property that no two tuples t1 and t2 in any legal relation state r of R will have t1[S] = t2[S]. A key K is a superkey with the additional property that removal of any attribute from K will cause K not to be a superkey any more.
The difference between a key and a superkey is that a key has to be minimal; that is, if we have a key K = {A1, A2, ..., Ak} of R, then K – {Ai} is not a key of R. Ex: {Ssn} is a key for EMPLOYEE, whereas {Ssn}, {Ssn, Ename}, {Ssn, Ename, Bdate}, and any set of attributes that includes Ssn are all superkeys. If a relation schema has more than one key, each is called a candidate key. One of the candidate keys is arbitrarily designated to be the primary key , and the others are called secondary keys. {Ssn} is the only candidate key for EMPLOYEE, so it is also the primary key. Definition. 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.
3. If a maximum number of values is known for the attribute for example, if it is known that at most three locations can exist for a department—replace the Dlocations attribute by three atomic attributes: Dlocation1, Dlocation2, and Dlocation3. This solution has the disadvantage of introducing NULL values if most departments have fewer than three locations.
First normal form also disallows multivalued attributes that are themselves composite. These are called nested relations because each tuple can have a relation within it. Figure 15.10 the EMP_PROJ relation represents an employee entity, and a relation PROJS (Pnumber, Hours) within each tuple. The schema of this EMP_PROJ relation can be represented as follows: EMP_PROJ (Ssn, Ename, {PROJS (Pnumber, Hours)}). The set braces { } identify the attribute PROJS as multivalued, and we list the component attributes that form PROJS between parentheses ( ). To normalize this into 1NF, we remove the nested relation attributes into a new relation and propagate the primary key into it; Decomposition and primary key propagation yield the schemas EMP_PROJ1 and EMP_PROJ2, as shown in Figure 15.10(c).
Figure 15.10 Normalizing nested relations into 1NF. (a) Schema of the EMP_PROJ relation with a nested relation attribute PROJS. (b) Sample extension of the EMP_PROJ relation showing nested relations within each tuple. (c) Decomposing EMP_PROJ into EMP_PROJ1 and EMP_PROJ2 by propagating the primary key.
3.4 Second normal form (2NF)
Definition. A relation schema R is in 2NF if every nonprime attribute A in R is fully functionally dependent on the primary key of R****.
Second normal form (2NF) is 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. Example1: {Ssn, Pnumber} → Hours is a full dependency (neither Ssn → Hours nor Pnumber→Hours holds). A functional dependency X → Y is a partial functional dependency if removal of any attribute A from X and the dependency still holds; Example2: The dependency {Ssn, Pnumber}→Ename is partial because Ssn→Ename holds. The EMP_PROJ relation is in 1NF but is not in 2NF. The nonprime attribute Ename violates 2NF because of FD2 , Pname and Plocation violates 2NF because of FD3.
Figure 15. (a) The LOTS relation with its functional dependencies FD1 through FD4. (b) Decomposing into the 2NF relations LOTS1 and LOTS2.
3.5 Third Normal Form (3NF)
Definition: A relation schema R is in 3NF if it satisfies 2NF and no nonprime attribute of R is transitively dependent on the primary key. Third normal form (3NF) is 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 such that X→Z and Z→Y hold. Ex: The dependency Ssn→Dmgr_ssn is transitive in EMP_DEPT, because of the dependencies Ssn → Dnumber and Dnumber → Dmgr_ssn.
Normalizing EMP_DEPT into 3NF relations.
The relation schema EMP_DEPT is not in 3NF because of the transitive dependency of Dmgr_ssn and Dname on Ssn via Dnumber. We can normalize EMP_DEPT by decomposing it into the two 3NF relation schemas ED1 and ED2 shown in the above figure.
Example 2:
FD4 in LOTS1 violates 3NF because Area is not a superkey and Price is not a prime attribute in LOTS1. To normalize LOTS1 into 3NF, we decompose it into the relation schemas LOTS1A and LOTS1B shown in Figure 15.12(c).We construct LOTS1A by removing the attribute Price that violates 3NF from LOTS1 and placing it with Area (the lefthand side of FD4 that causes the transitive dependency) into another relation LOTS1B. Both LOTS1A and LOTS1B are in 3NF.
Figure 15.12(c). Decomposing LOTS1 into the 3NF relations LOTS1A and LOTS1B.
4. Boyce-Codd Normal Form
Definition. 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****. The BCNF is based on the concept non trivial dependency. If an FD X → Y holds, where Y is not a subset of X, then it is called a non- trivial FD. FD5 violates BCNF in LOTS1A because AREA is not a superkey of LOTS1A. decompose LOTS1A into two BCNF relations LOTS1AX and LOTS1AY, shown in Figure 15.13(a).
Figure 15. Boyce-Codd normal form. (a) BCNF normalization of LOTS1A with the functional dependency FD2 being lost in the decomposition.
should also exist in r with the following properties, where we use Z to denote ( R – ( X ∪ Y)) t3[X] = t4[X] = t1[X] = t2[X]. t3[Y] = t1[Y] and t4[Y] = t2[Y]. t3[Z] = t2[Z] and t4[Z] = t1[Z].
An MVD X →→ Y in R is called a trivial MVD if (a) Y is a subset of X , or (b) X ∪ Y =
R. An MVD that satisfies neither (a) nor (b) is called a nontrivial MVD. For example, the relation EMP_PROJECTS in Figure 15.15(b) has the trivial MVD Ename →→ Pname. 15.15(b)
Definition. A relation schema R is in 4NF with respect to a set of dependencies F (that includes functional dependencies and multivalued dependencies) if, for every nontrivial multivalued dependency X →→ Y in F , X is a superkey for R****.
An all-key relation is always in BCNF since it has no FDs. An all-key relation such as the EMP relation in Figure 15.15(a), which has no FDs but has the MVD Ename→→ Pname | Dname, is not in 4NF.
A relation that is not in 4NF due to a nontrivial MVD must be decomposed To convert it into a set of relations in 4NF. The decomposition removes the redundancy caused by the MVD. Consider the EMP relation in Figure 15.15(a). EMP is not in 4NF because of the nontrivial MVDs Ename→→ Pname and Ename →→ Dname, and Ename is not a superkey of EMP. We decompose EMP into EMP_PROJECTS and EMP_DEPENDENTS, shown in Figure 15.15(b). Both EMP_PROJECTS and EMP_DEPENDENTS are in 4NF, because the MVDs Ename →→ Pname in EMP_PROJECTS and Ename →→ Dname in EMP_DEPENDENTS are trivial MVDs.
Figure 15. (a) The EMP relation with two MVDs: Ename →→ Pname and Ename →→ Dname. (b) Decomposing the EMP relation into two 4NF relations EMP_PROJECTS and EMP_DEPENDENTS.
Whenever we decompose a relation schema R into R 1 = ( X ∪ Y ) and R 2 = ( R – Y ) based on an MVD X →→ Y that holds in R , the decomposition has the nonadditive join property.
The following algorithm shows Relational Decomposition into 4NF Relations with Nonadditive Join Property. Input: A universal relation R and a set of functional and multivalued dependencies F.
1. Set D := { R }; 2. While there is a relation schema Q in D that is not in 4NF, do { choose a relation schema Q in D that is not in 4NF; find a nontrivial MVD X →→ Y in Q that violates 4NF; replace Q in D by two relation schemas ( Q – Y ) and ( X U Y ); }; 6. Join Dependencies and Fifth Normal Form
A relation schema R when divided in to R 1 and R 2 has the lossless property and if the natural join is applied (R1 * R 2 ) we will get the original relation R. In some cases there may be no lossless join decomposition of R if the number of decomposition is equal to two. But if the same relation is decomposed in to more than two relations we have a lossless decomposition. This dependency depends on the number of decomposition and hence referred as join dependency Definition. A join dependency ( JD ), denoted by JD( R 1, R 2, ..., Rn ), specified on relation schema R , specifies a constraint on the states r of R. The constraint states that every legal
to any two of these relations produces spurious tuples, but applying a natural join to all three together does not.
16. Relational Database Design Algorithms and Dependencies
Inference Rules for Functional Dependencies
The set of functional dependencies are specified by F on relation schema R, other functional dependencies can be inferred or deduced from the FDs in F. For example, Department has one manager, the Dept_no uniquely determines Mgr_ssn, and manager uniquely determines phone number called Mgr_phone then these two dependencies together imply that Dept_no → Mgr_phone. (Dept_no → Mgr_ssn), (Mgr_ssn→Mgr_phone), Dept_no → Mgr_phone This is an inferred FD and need not be explicitly stated in addition to the two given FDs. Therefore, it is useful to define a concept called closure formally that includes all possible dependencies that can be inferred from the given set F. Definition- The set of all dependencies that include F as well as all dependencies that can be inferred from F is called the closure of F; it is denoted by F+. For example, suppose that we specify the following set F of obvious functional dependencies on the relation schema in Figure 15.3(a): F = {Ssn → {Ename, Bdate, Address, Dnumber}, Dnumber → {Dname, Dmgr_ssn} } Some of the additional functional dependencies that we can infer from F are the following: Ssn → {Dname, Dmgr_ssn} Dnumber → Dname The closure F+ of F is the set of all functional dependencies that can be inferred from F. To determine a systematic way to infer dependencies, the set of inference rules are used to infer new dependencies from a given set of dependencies. The notation F |=X → Y to denote that the functional dependency X→Y is inferred from the set of functional dependencies F. The FD {X,Y}→Z is abbreviated to XY→Z, and the FD {X, Y, Z} → {U, V} is abbreviated to XYZ → UV.
Proof of IR1. Suppose that X ⊇ Y and that two tuples t1 and t2 exist in some relation instance r of R such that t1 [X] = t2 [X]. Then t1[Y] = t2[Y] because X ⊇ Y; hence, X→Y must hold in r.