This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
worked): The key for Hourly Emps is ssn. In addition, suppose that the hourly wages
attribute is determined by the rating attribute. That is, for a given ratingvalue, there is only one permissible hourly wages value. This Constraint isan example of a functional dependency. It leads to possible redundancy inthe relation Hourly Emps
Notation : We will denote this relation schema by listing the attributes:SNLRWH
– This is really the set of attributes {S,N,L,R,W,H}.
–
Sometimes, we will refer to all attributes of a relation by using the relationname. (e.g., Hourly_Emps for SNLRWH)
• Suppose that we have entity sets Parts, Suppliers, and
Departments, as well as a relationship set Contracts thatinvolves all of them. We refer to the schema for Contractsas CSDPQ . A contract with contract id C specifies that asupplier S will supply some quantity Q of a part P to adepartment D .
• We might have a policy that a department purchases atmost one part from any given supplier. Thus, if there areseveral contracts between the same supplier anddepartment,we know that the same part must be involved
Use of Decompositions• Intuitively, redundancy arises when a relational schema forces an
association between attributes that is not natural.
• Functional dependencies (ICs) can be used to identify suchsituations and to suggest modifications to the schema.
• The essential idea is that many problems arising from redundancycan be addressed by replacing a relation with a collection of smallerrelations.
• Each of the smaller relations contains a subset of the attributes ofthe original relation.We refer to this process as decomposition ofthe larger relation into the smaller relations
• Unless we are careful, decomposing a relation schema can createmore problems than it solves.
• Two important questions must be asked repeatedly:
–
Do we need to decompose a relation? – What problems (if any) does a given decomposition
cause?
• To help with the first question, several normal forms have beenproposed for relations.
• If a relation schema is in one of these normal forms, we knowthat certain kinds of problems cannot arise. The normal formsbased on FDs are first normal form (1NF), second normal form (2NF), third normal form (3NF), and Boyce-Codd normal form (BCNF).
•These forms have increasingly restrictive requirements: Everyrelation in BCNF is also in 3NF, every relation in 3NF is also in2NF, and every relation in 2NF is in 1NF.
• 3NF and BCNF are important from a database designstandpoint.
A relation is in first normal form if every field contains only
atomic values, that is, not lists or sets. This requirement isimplicit in our definition of the relational model even thoughsome of the newer database systems are relaxing thisrequirement
1NF (First Normal Form)
• a relation R is in 1NF if and only if it has only single-valuedattributes (atomic values)
• EMPLOYEE (SSN, emp_id, HOURS, ENAME, ADDRESS)
If the ADDRESS column has multiple values like streetaddress, city, state, pincode all in one column,then
EMPLOYEE is not in 1NF.• One needs to write a complex query for all employees living
• Simlarly, if emp_id consists of dept code and another uniquenumber within the department, it is NOT in 1NF.
• It requires extra programming to extract the departmentinformation of an employee. And, the information gets encodein he application rather than in the database.
• If the code is used a primary key, it can have more problems. Ifan employee changes his department, the primary key valuehas to be changed, particularly if there is a foreign keyreferencing this table. If it is not changed, it is a wrongrepresentation of data and may even lead to errors.
• Similarly, if all the account numbers of a customer are stored inone column and / or all the customers of an account numberare stored in one column, it leads to redundant storage andcomplex queries as well.
• Relationn R with FDs F is in 3NF if, for all X A in
– A X (called a trivial FD), or – X contains a key for R i.e. X is a super key, or
– A is part of some key for R.
• Minimality of a key is crucial in third condition above!
•
If R is in BCNF, obviously in 3NF.• If R is in 3NF, intuitively, a part of the key can depend on some other
part of the key. And, some redundancy is possible. It is acompromise, used when BCNF not achievable (e.g., no ``good’’ decomposition, or performance considerations).
– Lossless-join, dependency-preserving decomposition of R into a collection of 3NF relations always possible whereas dependency preservation may not be possible with BCNF.
• Relation R with FDs F is in BCNF if, for all X A in
– A X (called a trivial FD), or – X contains a key for R (if A is not a part of X)
• In other words, R is in BCNF if the only non-trivial FDs that hold overR are key constraints. This more restrictive than the 3NF. 3NF allowsthe FD when A is a part of another key.
• In the example below, if the above FD holds and the relation is inBCNF, X contains a key, the two tuples that agree upon the X valueshould also agree on Y value and hence, the 2 tuples must beidentical (since X is a key).
– Second FD causes violation of 3NF; W values repeatedlyassociated with R values. Easiest way to fix this is to create arelation RW to store these associations, and to remove W
from the main schema:• i.e., we decompose SNLRWH into SNLRH and RW
• The information to be stored consists of SNLRWH tuples. If we just store the projections of these tuples onto SNLRH and RW,are there any potential problems that we should be aware of?