Data-Normalization 677e35783b23e
Data-Normalization 677e35783b23e
CSE4005
Department Table
2
Mapping ER Diagrams into Relations
Employee
Name
EmpID
Address
Employee (EmpID, Name, Age, Address)
3
Mapping ER Diagrams into Relations
4
Mapping ER Diagrams into Relations
5
Mapping ER Diagrams into Relations
Hobby(SSN, Hobbyname)
6
Mapping ER Diagrams into Relations
Contract(cont_no, start, end, position, salary) Contract(cont_no, start, end, position, salary, emp_no)
7
Mapping ER Diagrams into Relations
8
Mapping ER Diagrams into Relations
Project(Project_ID, name,start_date)
Assign(Stu_ID, Project_ID)
9
Mapping ER Diagrams into Relations
When mapping a weak entity Primary key of the strong entity is taken to as a foreign key to the weak entity
Customer(Customer_id, customer_name)
Loan(Customer_id, loan_name)
10
Mapping ER Diagrams into Relations
Examples
Book(BookId, title)
Borrow(MemberID,BookID,dateTimeBorrowed,dateTimeReturned)
11
Mapping ER Diagrams into Relations
Examples
S (A, B, C) U (K ,L)
T ( P, Q, R) R (A , K, P, X )
12
Mapping ER Diagrams into Relations
Example 1 Assumptions
Lecturer can deliver many modules.
Students can have multiple mobile numbers.
Students can follow many courses.
Relational schema
Student(StNO, FName, LName, Address)
Follow(StNO, Course ID)
mobileNo(StNO, MobileNumber)
Course (Course ID, CourseName, DeptNo)
Department (DeptNo, DName)
Module (ModuleID, ModuleName, Course ID, Lecture ID )
Lecturer (Lecture ID, Name)
Leturer Qualifications(Lecturer ID, Quali_name)
13
Mapping ER Diagrams into Relations
Example 1
Student(StNo, FName, LName, Address)
Relational schema
mobileNo(StNo, MobileNumber)
M 1
has
1 1
Relational Schema
has
Account (Ac_no, Balance, b_name)
1 M Branch (b_name, b_city, Assets)
M
Borrow
Loan(L_no, Amt, b_name, C_name)
Customer(C_name, C_street, C_city)
15
Database Normalization
✓ Database normalization is a technique of organizing data in the database.
✓ Database normalization is the process of organizing the attributes of the database to reduce or
eliminate data redundancy (having the same data but at different places).
17
Database Normalization
Disadvantages
Reduction in efficiency of certain data retrieval as relations may be joined during retrieval.
Increase join
18
Database Normalization
Disadvantages
Reduction in efficiency of certain data retrieval as relations may be joined during retrieval.
Increase join
19
Database Normalization
Normalization Rules
20
Database Normalization
First Normal Form ( 1NF)
✓ A relation is in first normal form (1NF) if and only if all attributes are ATOMIC.
If each attribute is a primitive ( integer, real number, character string, but not lists or sets)
ATOMIC data
✓ Making your data is atomic is the first step in creating a NORMAL table.
21
Database Normalization
First Normal Form ( 1NF)
✓ For a table to be in the first normal form, it must meet the following criteria:
a single cell must not hold more than one value (atomicity)
each column must have only one value for each row in the table
22
Database Normalization
First Normal Form ( 1NF)
(employee_id, job_code)
form (1NF).
23
Database Normalization
First Normal Form ( 1NF)
24
Database Normalization
First Normal Form ( 1NF)
25
Database Normalization
Second Normal Form ( 2NF)
✓ A relation is in second normal form (2NF) if and only if it is in 1NF and every non key attribute is fully
3) Optimize relations
26
Database Normalization
Second Normal Form ( 2NF)
27
Employee_Job
Database Normalization
Second Normal Form ( 2NF)
2NF
Job Employee
28
Database Normalization
Third Normal Form ( 3NF)
✓ A relation is in third normal form (3NF) if and only if it is in 2NF and every non-key attribute is non transitively
✓ "Eliminate Columns not Dependent on Key," i.e., if attributes do not contribute to a description of a key,
29
Database Normalization
Third Normal Form ( 3NF) – Actions Required
1. Check each non-key attribute for dependency against other non-key fields
3. Create new relation comprising the attribute and non-key attribute which it depends on
30
Database Normalization
Third Normal Form ( 3NF) – Actions Required
31
Database Normalization
Third Normal Form ( 3NF) – Actions Required
Employee_Job Employee
Employee_Job
Employee
3NF
Job States
Job
32
Database Normalization
Exercise
33
Database Normalization
Exercise
1NF
34
Student_Course Student
Database Normalization
Exercise
2NF
Course
35
Database Normalization
Student_Course Student
Exercise
Student_Course Student
3NF
Course Faculty
Course
36
.
Thank you