MODULE4
MODULE4
Database Design
• coming up with a ‘good’ schema is very important
How do we characterize the “goodness” of a schema ?
If two or more alternative schemas are available
how do we compare them ?
What are the problems with “bad” schema designs ?
Normal Forms:
• Each normal form specifies certain conditions If the
conditions are satisfied by the schema
• certain kind of problems are avoided
An Example
•Incorrect schema:
• Student Dept
Decomposition
Lossless Dependency
decomposition preserving
A B C D
a1 b1 c1 D1
a1 b1 c1 d2
a1 b2 c2 d1
a2 b1 c3 d1
• To add a tuple <a1 ,b1 , c2 ,d1> to the instances is not possible because it
violates FD.
Reasoning About FDs
• Informal Definition
• F+ is the set of all FDs logically implied by F
•An FD X → Y where Y ⊆ X
- called a trivial FD, it always holds good
•An FD X → Y where Y ⊈ X
- non-trivial FD
•An FD X → Y where X ∩ Y =
•completely non-trivial FD
Deriving new FDs
•For instance,
• given that X → Y, Y → Z hold on R
we can infer that X → Z must also
hold
Relation R(A, B, C, D)
FDs:
A->B
B->D
C->B
A+ -> ABD
Closure(A)= ABD
NORMALIZATION & TYPES OF NORMALIZATION
NORMALIZATION
Normalization can be defined as :-
2 Green Rs.150
5 Black Rs.100
After decomposing it into first
normal form it looks like:
Product_id Price Product_id Colour
1 Rs.210 1 Black
1 Red
2 Rs.150
2 Green
3 Rs. 110 3 Red
4 Rs.260 4 Green
4 Blue
5 Rs.100
5 Black
EMPLOYEE table:
14 John 7272826385, UP
9064738238
14 John 7272826385 UP
14 John 9064738238 UP
3 2 Delhi
4 3 Noida
After decomposing it into second
normal form it looks like:
4 3 Travel 130
5 2 sports 140
After decomposing it into third
normal form it looks like:
TABLE BOOK TABLE GENRE
Book_id Genre_id Price Genre_id Genre type
1 1 100 1 Fiction
2 2 110
2 Sports
3 1 120
3 Travel
4 3 130
5 2 140
Boyce-Codd Normal Form (BCNF)
It is an advance version of 3NF that’s why it is also referred as
3.5NF.
BCNF is stricter than 3NF.
A table complies with BCNF if it is in 3NF and for every
functional dependency X->Y, X should be the super key of the
table.
Boyce-Codd Normal
Form
Student Course Teacher
Aman E-COMM
Abhinav DBMS
Loss less Join Decomposition
• Lossless decomposition ensures-
1 2 1
2 5 3
3 3 3
R2 , …. , Rn.
This decomposition is called lossy join decomposition when the join of the
sub relations does not result in the same relation R that was decomposed.
The natural join of the sub relations is always found to have some
extraneous tuples.
For lossy join decomposition, we always have
R1 ⋈ R2 ⋈ R3 ……. ⋈ Rn ⊃ R
2 5 3
3 3 3
A C B C
1 1 2 1
2 3
5 3
3 3
3 3
• Multivalued dependency
• Trivial functional dependency
• Non-trivial functional dependency
• Transitive dependency
• Inclusion dependency
Multivalued dependency in DBMS
Continued in next
Company Product
Coca cola company Thumps Up
Unilever Ponds
Unilever Axe
Unilever Lakme
Pepsico Pepsi
P&G Vicks
Introduction to Database Keys
What are DBMS Keys
• Student
SID NAME BRANCH EMAIL
3 Adam IT adamnerd@gmail.com
Surrogate key
Super
Composite &
Primary key
Compound key
Foreign key
Super Key
Super Key is defined as a set of attributes within a table that can
uniquely identify each record within a table. Super Key is a
SID Reg_ID
superset NAME
of Candidate key. BRANCH EMAIL
1 CS-37 John CSE john@gmail.com
2 CS-02 Adam CSE adamcool@gmail.com
3 IT-01 Adam IT adamnerd@gmail.com
4 ECE-07 Elly ECE elly@gmail.com
Keys:
SID SID + Reg_ID SID + Reg_ID + EMAIL
Reg_ID Reg_ID + EMAIL