Unit-3 DBMS
Unit-3 DBMS
12-03-2021 Side 2
Types of Functional Dependency
Trivial Functional Dependency
If a functional dependency (FD) X → Y holds, where Y is a
subset of X, then it is called a trivial FD. Trivial FDs always
hold.
A → B has trivial functional dependency if B is a subset of A.
The A → A, B → B dependencies are also trivial FDs.
Consider a table with two columns Employee_Id and
Employee_Name.
{Employee_id, Employee_Name} → Employee_Id is a trivial
functional dependency as Employee_Id is a subset of
{Employee_Id, Employee_Name}.
Also, Employee_Id → Employee_Id and Employee_Name →
Employee_Name are trivial dependencies too.
12-03-2021 Side 3
Types of Functional Dependency
Non-trivial Functional Dependency
If an FD X → Y holds, where Y is not a subset of X, then it
is called a non-trivial FD.
A → B has a non-trivial functional dependency if B is not a
subset of A.
When A intersection B is NULL, then A → B is called as
complete non-trivial.
Examples: ID → Name, Name → DOB
12-03-2021 Side 4
Armstrong's Axioms
If F is a set of functional dependencies then the closure of
F, denoted as F+, is the set of all functional dependencies
logically implied by F.
Armstrong's Axioms are a set of rules, when applied
repeatedly, generates a closure of functional dependencies.
The Armstrong's axioms are the basic inference rule.
Armstrong's axioms are used to conclude functional
dependencies on a relational database.
The inference rule is a type of assertion. It can apply to a
set of FD(functional dependency) to derive other FD.
Using the inference rule, we can derive additional
functional dependency from the initial set.
The Functional dependency has 6 types of inference rule:
12-03-2021 Side 5
Armstrong's Axioms
1. Reflexive Rule (IR1)
If X → Y and YZ → W then XZ → W
Proof:
1. X → Y (given)
2. YZ → W (given)
3. XZ → YZ (using IR2 on 1 by augmenting with Z)
4. XZ → W (using IR3 on 3 and 2)
12-03-2021 Side 9
Normalization
Normalization is a database design technique that reduces data
redundancy and eliminates undesirable characteristics like
Insertion, Update and Deletion Anomalies.
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.
12-03-2021 Side 11
Types of Normal Form
Normal Form Description
12-03-2021 Side 14
Examples of 1NF
EMPLOYEE:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE
14 John 7272826385 UP
14 John 9064738238 UP
20 Harry 8574783832 Bihar
12 Sam 7390372389 Punjab
12 Sam 8589830302 Punjab
12-03-2021 Side 15
Examples of 1NF
Here you see Movies Rented column has multiple values. Not in 1NF.
12-03-2021 Side 16
Second Normal Form (2NF)
A relation is said to be in 2NF if it is in 1NFand all non-key attributes are
fully functional dependent on the primary key i.e there is no partial
dependency.
Example: Let's assume, a school can store the data of teachers and the
subjects they teach. In a school, a teacher can teach more than one subject.
Teacher Table:
TEACHER_ID SUBJECT TEACHER_AGE
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
In the given table, non-prime attribute TEACHER_AGE is dependent on
TEACHER_ID which is a proper subset of a candidate key. That's why it
violates the rule for 2NF.To convert the given table into 2NF, we decompose
it into two tables:
12-03-2021 Side 17
Second Normal Form (2NF)
Candidate Keys: {teacher_id, subject}, Non prime attribute: teacher_age
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
12-03-2021 Side 18
Second Normal Form (2NF)
Member Details
Movies Rented
12-03-2021 Side 19
Third Normal Form (3NF)
A relation will be in 3NF if it is in 2NF and not contain any transitive
dependency.
3NF is used to reduce the data duplication. It is also used to achieve the data
integrity.
If there is no transitive dependency for non-prime attributes, then the relation
must be in third normal form.
A relation is in third normal form if it holds at least one of the following
conditions for every non-trivial function dependency X → Y.
X is a super key.
Y is a prime attribute, i.e., each element of Y is part of some candidate key.
Example
EMPLOYEE_DETAIL table:
EMP_ID EMP_NAME EMP_ZIP EMP_STATE EMP_CITY
Non-prime attributes: In the given table, all attributes except EMP_ID are
non-prime.
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.
12-03-2021 Side 21
Third Normal Form (3NF)
EMPLOYEE table:
EMP_ID EMP_NAME EMP_ZIP
EMPLOYEE_Zip table:
EMP_ZIP EMP_STATE EMP_CITY
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
12-03-2021 Side 22
Third Normal Form (3NF)
Suppose a company wants to store the complete address of each employee,
they create a table named employee_details that looks like this:
12-03-2021 Side 23
Third Normal Form (3NF)
Employee table:
emp_id emp_name emp_zip
1001 John 282005
1002 Ajeet 222008
1006 Lora 282007
1101 Lilly 292008
1201 Steve 222999
Employee_Zip table:
emp_zip emp_state emp_city emp_district
282005 UP Agra Dayal Bagh
222008 TN Chennai M-City
282007 TN Chennai Urrapakkam
292008 UK Pauri Bhagwan
222999 MP Gwalior Ratan
12-03-2021 Side 24
Third Normal Form (3NF)
Super keys: {emp_id}, {emp_id, emp_name}, {emp_id,
emp_name, emp_zip}…so on
Candidate Keys:{emp_id}
EMPLOYEE table:
EMP_ID EMP_COUNTRY EMP_DEPT DEPT_TYPE EMP_DEPT_NO
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
12-03-2021 Side 27
Boyce Codd normal form (BCNF)
EMP_DEPT table:
EMP_DEPT DEPT_TYPE EMP_DEPT_NO
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
12-03-2021 Side 28
Boyce Codd normal form (BCNF)
Example 2:
Consider a relation given below:
SP (Sno, Sname, Pno, Qty), Here Sname is considered unique for
each Sno. So, FD of above relation is:
(Sno, Pno) → Qty, (Sname, Pno) → Qty, Sno →Sname
Sname → Sno. Is this relation in 3NF? Check for it to be in BCNF?
How can you solve this problem?
SN (Sno, Sname)
SPP (Sno, Pno, Qty).
Here, SN relation has two determinants, and both are unique.
SPP has one determinant (Sno, Pno) and is also unique.
Thus, all the anomalies are removed.
12-03-2021 Side 30
Fourth normal form (4NF)
A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-
valued dependency.
For a dependency A → B, if for a single value of A, multiple values of B exists,
then the relation will be a multi-valued dependency.
STUDENT
STU_ID COURSE HOBBY
21 Computer Dancing
21 Math Singing
34 Chemistry Dancing
74 Biology Cricket
59 Physics Hockey
The given STUDENT table is in 3NF, but the COURSE and HOBBY are two
independent entity. Hence, there is no relationship between COURSE and
HOBBY.
In the STUDENT relation, a student with STU_ID, 21 contains two
courses, Computer and Math and two hobbies, Dancing and Singing. So, there
is a Multi-valued dependency on STU_ID, which leads to unnecessary
12-03-20r21epetition of data. Side 33
Fourth normal form (4NF)
So, to make the above table into 4NF, we can decompose it into two tables:
STUDENT_COURSE
STU_ID COURSE
21 Computer
21 Math
34 Chemistry
74 Biology
59 Physics
STUDENT_HOBBY
STU_ID HOBBY
21 Dancing
21 Singing
34 Dancing
74 Cricket
59 Hockey
12-03-2021 Side 32
Fifth normal form (5NF)
A relation is in 5NF if it is in 4NF and not contains any join
dependency and joining should be lossless.
5NF is satisfied when all the tables are broken into as many tables as
possible in order to avoid redundancy.
Semester 1 Computer
Semester 1 Math
Semester 1 Chemistry
Semester 2 Math
12-03-2021 Side 34
P2
Fifth normal form (5NF)
SUBJECT LECTURER
Computer Anshika
Computer John
Math John
Math Akash
Chemistry Praveen
P3
SEMSTER LECTURER
Semester 1 Anshika
Semester 1 John
Semester 1 John
Semester 2 Akash
Semester 1 Praveen
12-03-2021 Side 35
Relational Decomposition
When a relation in the relational model is not in appropriate normal
form then the decomposition of a relation is required.
In a database, it breaks the table into multiple tables.
If the relation has no proper decomposition, then it may lead to
problems like loss of information.
Decomposition is used to eliminate some of the problems of bad
design like anomalies, inconsistencies, and redundancy.
Types of Decomposition
12-03-2021 Side 36
Lossless Decomposition
If the information is not lost from the relation that is decomposed, then the
decomposition will be lossless.
The lossless decomposition guarantees that the join of relations will result
in the same relation as it was decomposed.
The relation is said to be lossless decomposition if natural joins of all the
decomposition give the original relation.
EMPLOYEE_DEPARTMENT table
EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME
12-03-2021 Side 37
Lossless Decomposition
The above relation is decomposed into two relations EMPLOYEE & DEPARTMENT.
EMPLOYEE table
EMP_ID EMP_NAME EMP_AGE EMP_CITY
22 Denim 28 Mumbai
33 Alina 25 Delhi
46 Stephan 30 Bangalore
52 Katherine 36 Mumbai
60 Jack 40 Noida
DEPARTMENT table
DEPT_ID EMP_ID DEPT_NAME
827 22 Sales
438 33 Marketing
869 46 Finance
575 52 Production
678 60 Testing
12-03-2021 Side 38
Lossless Decomposition
Now, when these two relations are joined on the common column "EMP_ID",
then the resultant relation will look like:
Employee ⋈ Department
EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME
12-03-2021 Side 40
Multivalued Dependency
Multivalued dependency occurs when two attributes in a table are
independent of each other but, both depend on a third attribute.
A multivalued dependency consists of at least two attributes that are
dependent on a third attribute that's why it always requires at least three
attributes. Suppose there is a bike manufacturer company which produces
two colours (white and black) of each model every year.
12-03-2021 Side 41
Multivalued Dependency
Here columns COLOR and MANUF_YEAR are dependent on
BIKE_MODEL and independent of each other.
BIKE_MODEL → → MANUF_YEAR
BIKE_MODEL → → COLOR
12-03-2021 Side 42
Join Dependency
Join decomposition is a further generalization of Multivalued
dependencies.
If the join of R1 and R2 over C is equal to relation R, then we can say
that a join dependency (JD) exists.
Where R1 and R2 are the decompositions R1(A, B, C) and R2(C, D) of a
given relations R (A, B, C, D).
Here, *(R1, R2, R3) is used to indicate that relation R1, R2, R3 and so
on are a JD of R.
12-03-2021 Side 45
Inclusion Dependency
Multivalued dependency and join dependency can be used to guide database design
although they both are less common than functional dependencies.
Inclusion dependencies are quite common. They typically show little influence on
designing of the database.
The inclusion dependency is a statement in which some columns of a relation are
contained in other columns.
The example of inclusion dependency is a foreign key. In one relation, the referring
relation is contained in the primary key column(s) of the referenced relation.
Suppose we have two relations R and S which was obtained by translating two entity
sets such that every R entity is also an S entity.
Inclusion dependency would be happen if projecting R on its key attributes yields a
relation that is contained in the relation obtained by projecting S on its key attributes.
In inclusion dependency, we should not split groups of attributes that participate in an
inclusion dependency.
In practice, most inclusion dependencies are key-based that is involved only keys.
12-03-2021 Side 44
Canonical Cover
In the case of updating the database, the responsibility of the system
is to check whether the existing functional dependencies are getting
violated during the process of updating.
In case of a violation of functional dependencies in the new database
state, the rollback of the system must take place.
A canonical cover or irreducible a set of functional dependencies FD
is a simplified set of FD that has a similar closure as the original set
FD.
12-03-2021 Side 45