Professional Documents
Culture Documents
2
Normalization
4
Normalization
5
Normalization
New Student Table New Branch Table
6
Normalization
7
Normalization
4. Etc.
8
1st Normal Form (1NF)
Table 1 Rule 1
9
1st Normal Form (1NF)
Table 2 Rule 2
10
1st Normal Form (1NF)
Table 3 Rule 3
11
1st Normal Form (1NF)
Table 4 Rule 4
12
1st Normal Form (1NF)
• Table 5 Violates 1NF.
Table 5
• How to solved this?
Rollno Name Subject
101 Akon OS,NET • All what, we have to do is
103 Ckon JAVA to break the values into
102 Bkon C, C++ down values, by doing so
few values are getting
repeated.
13
1st Normal Form (1NF)
• But values for subject
Table 6
column is now atomic for
Rollno Name Subject
each row. Hence, the
101 Akon OS
101 Akon NET table is in 1NF.
103 Ckon JAVA
102 Bkon C
102 Bkon C++
14
2nd Normal Form (2NF)
2. Why is it so important?
15
2nd Normal Form (2NF)
Student_id Name Regno Branch Address
1 Akon CSE-18 CSE TN
2 Akon IT-18 IT AP
3 Bkon CSE-18 CSE HR
4 Ckon CSE-18 CSE MH
10 Akon CSE-18 CSE TN
16
2nd Normal Form (2NF)
18
2nd Normal Form (2NF)
Subject Table
Subject_id Subject_name
1 Java
2 C++
4 DB
19
2nd Normal Form (2NF)
Score Table
Score_id Student_id Subject_id Marks Teacher
1 1 1 82 Allan
2 1 2 77 Kamali
3 2 1 85 Allan
4 2 2 82 Kamali
5 2 4 95 Jacqueline
21
2nd Normal Form (2NF)
• Because we have many to many relationship
22
2nd Normal Form (2NF)
25
3rd Normal Form (3NF)
26
3rd Normal Form (3NF)
Score_id Student_id Subject_id Marks Exam_name Total_marks
28
3rd Normal Form (3NF)
• What about the second new column Total_marks? Does it
depend on the primary key? Or some other column?
• Total_marks depends on exam_name.
• Thinking how?
i. Practicals are of 40 marks
ii. Main exams are of 70 marks
iii. Sessional are 50 marks
29
3rd Normal Form (3NF)
30
3rd Normal Form (3NF)
Student table
Student_id Name Regno Branch Address
Score table
Score_id Student_id Subject_id Marks Exam_name
31
3rd Normal Form (3NF)
Subject table
Subject_id Subject_name teacher
Exam table
Exam_name Total_marks
32
Relational Algebra
• Data manipulation languages: relational algebra and
SQL.
• intersection, division,
37
Relational Algebra
1. Selection Operation
38
Relational Algebra
Selection Operation
Employees Relation
Selection Operation
40
Relational Algebra
Selection Operation
Employees Relation
Emp_name=Sandy were
selected.
41
Relational Algebra
42
Relational Algebra
43
Relational Algebra
• A valid formula: (A=B or A<C).
π
2) The projection PJAttrR ( AttrR) where Attr denotes a subset of
attributes of the operand relation, produces a result having
these attributes as a relation schema.
• The tuples of the result are divided from the tuples of the
operand relation by suppressing the values of attributes which
do not appear in Attr.
44
Relational Algebra
• Moreover, replicated tuples which might result from this
operation are eliminated; thus; the cardinality of the result
might be less than the cardinality of the operand.
45
Relational Algebra
• The binary operations take two relations as operands; we
review Union, difference, Cartesian product, intersect, join
and semi-join.
• Union combines all the rows in one table with all of the
rows in another table except for the duplicate tuples.
48
Relational Algebra
• relations R and S with the same relation schema;
49
Relational Algebra
• Basically it subtracts one table from the other table to
leave only attributes that are not the same in both tables.
A B C A B C B C D
R,S and T are
a 1 a a 1 a 1 a 1
operand relations
b 1 b a 3 r 1 a 1
a 1 d 3 c 2
b 2 f 1 d 4
2 a 3
52
Relational Algebra
Selection SLA=a R Projection PJA,B R
In rel. Alg. πA,B R
A B C A B One row has been repeated
a 1 a a 1 (a,1), as the rule stipulates “
a 1 d b 1 replicated tuples which
b 2
In Rel. Alg. It’s written as might result from the
σA=a R Projection
eliminated”.
operation are
53
Relational Algebra
Cartesian Product R CP S Union R UN S
R.A R.B R.C S.A S.B S.C
A B C A B C
a 1 a a 1 a
a 1 a b 1 b
b 1 b a 1 a
a 1 d a 1 a
b 1 b a 1 d
b 2 f a 1 a a 1 d b 2 f
a 1 a a 3 r b 2 f
a 3 r Difference R DF S
b 1 b a 3 r
a 1 d a 3 r
b 2 f a 3 r
54
Relational Algebra
55
Relational Algebra
R JN F S=SL F (R CP S)
56
Relational Algebra
57
Exercises-Relational Algebra
Stud_num name Age Dept
3 Jones 27 MSPE
7 Smith 34 HLE
11 Bob 18 HLE
15 Jane 23 ECE
18 Mary 31 MSPE
students table
58
Exercises-Relational Algebra
1) Write SQL query to select Stud_num and name.
3) Write SQL query to select all students with age below than 25.
59
Exercises-Relational Algebra (Answ.)
1) SELECT Stud_num, name from students;
4) σAge<25 (students)
60