204- SQLUnit 3
204- SQLUnit 3
Functional Dependencies
• Functional Dependency avoids data redundancy. That is, same data do
not repeat at multiple locations in that database
• It is a constraint that determines the relation of one attribute to another
attribute in a Database Management System (DBMS)
• It helps you to maintain the quality of data in the database
• It helps you to defined meanings and constraints of databases
• It helps you to identify bad designs
• It helps you to find the facts regarding the database design
Four types of functional dependency are
1) Multivalued
2) Trivial
3) Non-trivial
4) Transitive
X → Y (X determines Y)
The left side of FD is known as a determinant the right side of the production is
known as a dependent.
Emp_Id → Emp_Name
If we can check functional dependency A—>B then always all A value get one B
value Which can be never change. IF Value can be change then there is no
functional dependency.
Normalization
o Normalization is the process of organizing the data in the database.
o 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.
o Normalization divides the larger table into the smaller table and links
them using relationship.
o The normal form is used to reduce redundancy from the database table.
o Normalization is the process of splitting relations into well structured
relations that allow users to insert, delete, and update tuples without
introducing database.
o Without normalization many problems can occur when trying to load an
integrated conceptual model into the DBSM.
o These problems arise from relations that are generated directly from user
views are called anomalies.
14 John 7272826385, UP
9064738238
The decomposition of the EMPLOYEE table into 1NF has been shown below
14 John 7272826385 UP
14 John 9064738238 UP
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
To convert the given table into 2NF, we decompose it into two tables:
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
Third Normal Form (3NF)
o A relation will be in 3NF if it is in 2NF and not contain any transitive
partial dependency.
o 3NF is used to reduce the data duplication. It is also used to achieve the
data integrity.
o If there is no transitive dependency for non-prime attributes, then the
relation must be in third normal form.
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate
key.
Example:
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.
EMPLOYEE table:
EMPLOYEE_ZIP table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
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 into three tables:
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
Now, this is in BCNF because left side part of both the functional dependencies
is a key.