Bilal DBMS Unit-3
Bilal DBMS Unit-3
DB
MANAGEMENT
UNIT-3 M
Presented By
S Mohammad Bilal J
SYSTEM Assistant professor
Department I.T
VCE
UNIT-3
Redundancy: refers to repetition of same data or duplicate copies of same data stored in different locations.
Anomalies: Anomalies refers to the problems occurred after poorly planned and un-normalized databases where all the
data is stored in one table which is sometimes called a flat file database.
ANOMALIES or PROBLEMS FACING WITHOUT NORMALIZATION
✓ Anomalies refers to the problems occurred after poorly planned and
unnormalized databases where all the data is stored in one table which is
sometimes called a flat file database.
✓ Let us consider such type of schema.
✓ Here all the data is stored in a single table which causes redundancy of data or
say anomalies as SID and Sname are repeated once for same CID .
✓ Due to redundancy of data we may get the following problems, those are-
insertion anomalies : It may not be possible to store some information unless
some other information is stored as well.
redundant storage: some information is stored repeatedly
ANOMALIES OR PROBLEMS FACING WITHOUT NORMALIZATION
Deletion Anomaly:
✓ Deletion of S3 student cause the deletion of course. Because of deletion of some data forced to delete some
other useful data.
PURPOSE OF NORMALIZATION:
✓ Minimize the redundancy in data.
✓ Remove insert, update, and delete anomalies during the database activities.
✓ Normalization reduces a complex user view to a set of small and sub groups of fields or relations.
ADVANTAGES OF NORMALIZATION:
✓ The amount of unnecessary redundant data reduced.
✓ Data integrity is easily maintained within the database.
✓ The database & application design processes are much for flexible.
✓ Security is easier to maintain or manage.
DISADVANTAGES OF NORMALIZATION:
✓ Performance: all the joins required to merge data slow processing & place additional stress on your hardware.
✓ Complex queries: developers have to code complex queries in order to merge data from different tables.
Decomposition
✓ Decomposition in DBM is to break a relation into multiple relations to bring it into an appropriate normal form.
✓ It helps to remove redundancy, inconsistencies, and anomalies from a database.
✓ The decomposition of a relation R in a relational schema is the process of replacing the original relation R with two
or more relations in a relational schema.
Rules of decomposition:
✓ If ‘R’ is a relation splitted into ‘R1’ and ‘R2’ relations, the decomposition done should satisfy Following:
1)Union of two smaller subsets of attributes gives all attributes of ‘R’.
R1(attributes)UR2(attributes)=R(attributes)
2)Both relations interaction should not give null value.
R1(attributes)∩R2(attributes)!=null
3) Both relations interaction should give key attribute.
R1(attribute)∩R2(attribute)=R(key attribute)
Properties of Decomposition
1.Lossless decomposition:
✓ while joining two smaller tables no data should be lost and should satisfy all the rules of decomposition.
✓ No additional data should be generated on join of decomposed tables.
2. Dependency Preservation:
✓ None of the functional dependencies that holds on the original relation are lost.
✓ The sub relations still hold or satisfy the functional dependencies of the original relation.
Types of Decomposition:
Types of Decomposition
1. Lossless Join Decomposition:
✓ Consider there is a relation R which is decomposed into sub relations R1 , R2 , …. , Rn.
✓ This decomposition is called lossless join decomposition when the join of the sub relations results in the
same relation R that was decomposed.
Types of Decomposition
Example 2
Types of Decomposition
ii. Lossy join decomposition:
✓ If information is lost after joining and if do not satisfy any one of the rules of decomposition.
Functional Dependency
✓ Functional Dependencies are fundamental to the process of Normalization i.e., Functional Dependency plays key
role in differentiating good database design from bad database designs.
✓ It describes the relationship between attributes (columns) in a table.
✓ It is represented by an arrow sign (→).
Ex: A dependency FD: “X → Y” means that the values of Y are determined by the values of X.
✓ An attribute on left hand side is known as “Determinant”. Here X is a Determinant.
Example: Example:
Q2. R (A, B, C, D,E) and set of Functional Q3. R (A, B, C, D,E,F,G) and set of Functional
Dependencies are A→B, B→C, C→D, D→A, then Dependencies are A→BC, BC→DE, D→F, CF→G, then
what is the Closure of A, B, C, D,E? what is the Closure of A+, D+,(B,C,D)+?
Solution: Solution:
A+→ {A, B,C, D} A+→ {A, B,C, D,E,F,G}
B+→ { B, C,D,A} D+→ {D,F}
C+→ {C, D,A,B} (B,C,D)+→ {B,C,D,E,F,G}
D+→ {D,A,B,C}
E+→ {E}
Types of Functional Dependencies
1.Fully Functional Dependency:
✓ A functional dependency is said to be full dependency “if and only if the determinant of the functional dependency if
either candidate key or super key, and the dependent can be either prime or non-prime attribute”.
✓ Let’s take the functional dependency X → Y (i.e., X determines y). Here Y is said to be fully dependent, if it cannot
determine any subset of X.
Example:
✓ Consider the following determinant ABC → D i.e., ABC determines D but D is not determined by any subset of A/
BC/C/B/AB i.e., BC→D, C→D, A→D Functional dependencies are not exists. So D is Fully Functional Dependent.
2.Partial Functional Dependency:
✓ If a non-prime attribute of the relation is getting derived by only a part of the candidate key, then such dependency
is known as Partial Dependency.
Example:
✓ Consider the following determinants AC→P, A→D, D→P. From these determinants P is not fully FD on AC. Because, If
we find A+ (means A’s Closure) A→D, D→P i.e., A→P. But we don’t have any requirement of C. So P is Partially
Dependent on AC.
Types of Functional Dependencies
✓ Under the following conditions a table cannot have partial F.D
i. If primary key consists a single attribute
ii. If table consists only two attributes
iii. If all the attributes in the table are part of the primary key
3.Transitive Functional Dependency:
✓ If a non-prime attribute of a relation is derived by either another non-prime attribute or the combination of the
part of the candidate key along with non-prime attribute, then such dependency is defined as Transitive
dependency.
Example:
✓ X→Y, and Y→Z then we can determine X→Z holds.
✓ Under the following Circumstances, a table cannot have transitive F.D
i. If table consists only two attributes
ii. If all the attributes in the table are part of the primary key.
Types of Functional Dependencies
4.Trivial Functional Dependency:
✓ It is basically related to Reflexive rule. i.e., if X is a set of attributes, and Y is subset of X then X→Y holds.
Example:
✓ ABC→BC is a Trivial Dependency.
5.Multi-Valued Dependency:
✓ Consider 3 fields X, Y, and Z in a relation.
✓ Multi-valued Dependency. i.e., X → → Y Z or X → → Y/ Z
✓ Y and Z should not be dependent.(means Y->Z or Z->Y Should not be functionally dependent)
✓ If for each value of X, there is a well-defined set of values Y and Well-defined set of values of Z
✓ Set of values of Y is independent of the set values of Z.
Normal Forms
✓ Normalization means “split the tables into small tables which will contain less number of attributes in such a way
that table design must not contain any problem of inserting, deleting, updating anomalies and guarantees no
redundancy”.
✓ The evolution of Normalization theories / Steps of Normalization / Different Normal Forms:
i. First Normal Form (1NF)
ii. Second Normal Form (2NF)
iii. Third Normal Form (3NF)
iv. Boyce-Codd Normal Form (BCNF)
v. Fourth Normal Form (4NF)
vi. Fifth Normal Form (5NF).
Note:
✓ 1 NF is a mandatory NF and remaining are the optional
✓ If you construct E-R diagrams in to the tables, then 4 NF and 5 NF need not be applied on the table.
✓ Practically applied normalization is upto 3NF and very rarely we will go beyond that.
✓ 2 NF dealing with the partial dependencies and 3NF is dealing with transitive dependencies.
Normal Forms
i. First Normal Form (1NF)
✓ A relation is said to in the 1NF if it is already in un-normalized form and it satisfies the following conditions or rules
or qualifications are:
i. Each attribute name must be unique.
ii. Each attribute value must be single or atomic i.e., Single Valued Attributes.
iii. Each row / record must be unique.
iv. There is no repeating group’s.
How do we bring an un-normalized table into first normal form?
Example: Consider the following relation:
Solution:
✓ This table is not in first normal form because the [Color] column can
contain multiple values.
✓ First row includes values "red" and "green."
✓ To bring this table to first normal form, we split the table into two
tables.
i. First Normal Form (1NF)
A B C B D
iii. Third Normal Form (3NF)
✓ A database is in third normal form if it satisfies the following
conditions:
i. It is in 2NF.
ii. There is no transitive functional dependency
✓ Transitive functional dependency means we have the following
relationships in the table:
✓ A is functionally dependent on B, and B is functionally dependent
on C. In this case, C is transitively dependent on A via B.
✓ In the table, [Book ID] determines [Genre ID], and [Genre ID]
determines [Genre Type]. Therefore, [Book ID] determines [Genre
Type] via [Genre ID] and we have transitive functional dependency,
and this structure does not satisfy third normal form.
✓ To bring this table to third normal form, we split the table into two
as follows:
iii. Third Normal Form (3NF)
Q1. Given relation R(ABCDE) and F:{AB->C, B->D, D->E} Decompose in into 3NF.
✓ From the given FDs determine primary key.
✓ Necessary attributes to include in the key are A, B (because this attributes are not in RHS of FD).
✓ Find the closure set of AB
AB+ = {A,B,C}
={A,B,C,D} (∵ B->D)
= {A,B,C,D,E} (∵ D-> E)
AB is a primary key.
✓ From the FDs B->D is partially depending on AB. So decompose the table. (D is a non-prime attribute derived by a
part of the key)
B+ = BDE
iii. Third Normal Form (3NF)
✓ Now, the table is in 2NF but not in 3NF.
✓ Because D->E is transitive dependency. (No non-key attribute should determining a non-key attribute)
✓ D+ = {D,E}
Table is 3NF.
The relations after decomposing into 3NF.
R1:ABC
R2:BD
R3:DE
iv. Boyce-Codd normal form (BCNF)
✓ A relation is said to be in BCNF, if and only if every determinant should be a candidate key.
✓ BCNF is the advance version of 3NF. It is stricter than 3NF.
✓ A table is in 3NF if for every functional dependency X → Y, X is the super key of the table.
Example:
✓ Let's assume there is a company where employees work in more than one department. EMPLOYEE table:
✓ Multi Valued Dependency: A table is said to have multi-valued dependency, if the following conditions are true:
i. For a dependency A → B, if for a single value of A, multiple value of B exists, then the table may have multi-
valued dependency.
iii. And, for a relation R (A, B, C), if there is a multi-valued dependency between, A and B, then B and C should be
independent of each other.
✓ If all these conditions are true for any relation (table), it is said to have multi-valued dependency.
v. Fourth Normal Form (4NF)
Example:
✓ 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 relation, 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.
✓ So to make the above table into 4NF, we can decompose it into two tables:
vi. 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.
✓ 5NF is also known as Project-join normal form.
✓ A relation R is in 5NF if and only if it satisfies following conditions:
i. R should be already in 4NF.
ii. It cannot be further non loss decomposed (join dependency)
vi. Fifth Normal Form (5NF)
vi. Fifth Normal Form (5NF)
✓ The natural join of PI and P2 IS taken, the result ✓ Now, if this result is joined with P3 over the column
is: company ,product_name the following table is obtained:
K H
N A