Professional Documents
Culture Documents
DBMS Unit-3
DBMS Unit-3
CS3CO25 DBMS
Keys in DBMS
Presented By:
Safdar Sardar Khan
Asst. Prof., CSE 1
Unit III
Database Design: Design Guidelines, Key concepts, Relational Database Design,
Integrity Constraints, Domain Constraints, Referential Integrity, Functional
Dependency, decomposition.
Normalization Using Functional Dependencies: Normal Forms, First, Second and
Third Normal Forms. Boyce Codd Normal Form, Multivalued Dependencies and
Forth Normal Form, Join Dependencies and Fifth Normal Form, Decomposition in
2NF, 3NF and BCNF.
– Super Key
– Candidate Key
– Primary Key
– Foreign Key
CS3CO25 DBMS
Presented By:
Safdar Sardar Khan
Prepared and compiled by Asst. Prof., CSE 9
Safdar Sardar Khan, Asst. Professor, CSE
• Integrity constraints are set of rules. They are used to maintain
the quality of information.
• Integrity constraints ensure that the data insertion, updating, and
other processes have to be performed in such a way that data
integrity is not affected.
• Thus, integrity constraint is used to guard against accidental
damage to the database.
Integrity Constraints
“if there are two relations R1 & R2 having primary key K1 & K2
respectively and a subset α in R2 referencing to primary key K1 in R1
then for every tuple t2 in R2, there must be a tuple t1 in R1such that:
t2[α] =t1 [k1]
This concept is called Referential Integrity”
R1 R2
K1 K2 α β
t2 ABC
t1 ABC
CS3CO25 DBMS
Presented By:
Safdar Sardar Khan
Asst. Prof., CSE19
• Functional dependency in DBMS, as the name suggests is a relationship
between attributes of a table dependent on each other.
• Introduced by E. F. Codd, it helps in preventing data redundancy and gets to
know about bad designs.
Let we have a Department table with two attributes − DeptId and DeptName.
• Here, DeptId uniquely identifies the DeptName attribute. This is because if
you want to know the department name, then at first you need to have the
DeptId.
DeptId DeptName
001 Finance
002 Marketing
003 HR
• Union Rule :
if α -> β and α -> γ holds then α -> β γ will also hold.
• Decomposition Rule :
if α -> β γ holds then and α -> β & α -> γ will also hold.
For example:
Consider a table with columns Student_id and Student_Name.
{Student_Id, Student_Name} -> Student_Id is trivial FD.
For example:
An employee table with attributes: emp_id, emp_name, emp_address.
The following functional dependencies are non-trivial:
emp_id -> emp_name (emp_name is not a subset of emp_id)
emp_id -> emp_address (emp_address is not a subset of emp_id)
There are three steps to calculate closure of functional dependency. These are:
• Step-1 : Add the attributes which are present on Left Hand Side in the original
functional dependency.
• Step-2 : Now, add the attributes present on the Right Hand Side of the functional
dependency.
• Step-3 : With the help of attributes present on Right Hand Side, check the other
attributes that can be derived from the other given functional dependencies. Repeat this
process until all the possible attributes which can be derived are added in the closure.
{Marks} + = {Marks}
{Location} + ={Location}
• There are three steps to calculate the canonical cover for a relational schema
having set of functional dependencies.
Solution:
In above dependencies, FD3 (i.e. A->C) is redundant because it can be derived from FD1 &
FD2 using transitivity rule.
CS3CO25 DBMS
Decomposition in DBMS
Presented By:
Safdar Sardar Khan
Asst. Prof., CSE35
• Decomposition of a relation is done when a relation in relational model is not
in appropriate normal form.
2. Dependency Preservation
3.Common attribute must be a key for at least one relation (R1 or R2)
Att(R1) ∩ Att(R2) -> Super Key of R1 or R2
R1 ∩ R2 → R1
OR
R1 ∩ R2 → R2
Prepared and compiled by
Safdar Sardar Khan, Asst. Professor, CSE
Prepared and compiled by
Safdar Sardar Khan, Asst. Professor, CSE
Prepared and compiled by
Safdar Sardar Khan, Asst. Professor, CSE
Example :
Assume R(A, B, C, D) with FDs A→B, B→C, C→D.
Let us decompose R into R1 and R2 as follows;
R1(A, B, C)
R2(C, D)
Then find decomposition is dependency preserving or not?
Solution:
The FDs A→B, and B→C are hold in R1.
The FD C→D holds in R2.
Since, all the functional dependencies hold here. Hence, this decomposition is
dependency preserving.
Normalization in RDBMS
Presented By:
Safdar Sardar Khan
Asst. Prof., CSE45
• Normalization is the process of organizing the data in the database.
• Normalization is used to minimize the redundancy from a relation or set of
relations.
• It is also used to eliminate the undesirable characteristics like Insertion,
Update and Deletion Anomalies.
• Normalization divides the larger table into the smaller table and links them
using relationship.
• Let’s discuss about anomalies first then we will discuss normal forms with
examples.
The above table is not normalized. We will see the problems that we face when a
table is not normalized.
•In the above table we have two rows for employee Raman as he belongs to two
departments of the company.
•If we want to update the address of Raman then we have to update the same in
two rows or the data will become inconsistent.
•Suppose a new employee joins the company, who is under training and currently
not assigned to any department.
•Then we would not be able to insert the data into the table if Emp_dept field
doesn’t allow Nulls.
For a table to be in the First Normal Form, it should follow the following
rules:
•It should only have single (atomic) valued attributes/columns.
•Values stored in a column should be of the same domain
•Two employees (Jay & Lokesh) are having two mobile numbers so the company
stored them in the same field as you can see in the table above.
•This table is not in 1NF as the rule says “each attribute of a table must have
atomic (single) values”, the emp_mobile values for employees Jay & Lokesh
violates that rule.
emp_contact
Or
TEACHER_DETAIL TEACHER_SUBJECT
25 30 25 Chemistry
47 35 25 Biology
83 38 47 English
97 35 83 Math
83 Chemistry
Transitive dependency-
if α -> β and β ->γ hold,
then α -> γ will also holds
That's why we need to move the EMP_CITY and EMP_STATE to the new <EMPLOYEE_ZIP>
table, with EMP_ZIP as a Primary key.
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.
To convert the given table into BCNF, we decompose it.
Candidate keys:
For the first table: EMP_ID Now, this is in BCNF because left
For the second table: EMP_DEPT side part of both the functional
dependencies is a key.
For the third table: {EMP_ID, EMP_DEPT}
Prepared and compiled by
Safdar Sardar Khan, Asst. Professor, CSE
A table is said to be in the Fourth Normal Form when,
OR
If all above three are true then a table is having multivalued dependency.
5NF is satisfied when all the tables are broken into as many tables as possible in
order to avoid redundancy.