0% found this document useful (0 votes)
5 views37 pages

Data-Normalization 677e35783b23e

The document provides an overview of relational schemas and data normalization in database design, detailing how to map ER diagrams into relations and the various types of attributes. It explains the process of normalization, its advantages and disadvantages, and outlines the rules for achieving different normal forms (1NF, 2NF, 3NF). Additionally, it includes examples and exercises to illustrate the concepts discussed.

Uploaded by

ayanthachathu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views37 pages

Data-Normalization 677e35783b23e

The document provides an overview of relational schemas and data normalization in database design, detailing how to map ER diagrams into relations and the various types of attributes. It explains the process of normalization, its advantages and disadvantages, and outlines the rules for achieving different normal forms (1NF, 2NF, 3NF). Additionally, it includes examples and exercises to illustrate the concepts discussed.

Uploaded by

ayanthachathu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Database Design & Development

CSE4005

Relational Schemas & Data Normalization

W.R.A. Amasha Rathnayake


MSc in Big Data Analytics, Robert Gordon University
BSc (Hons) in Industrial Statistics, University of Colombo
Relational Schemas
✓ Relation schema defines the design and structure of the relation or table in the database.

Ex: Student Table

student (StuNo, name, degree, year, sex, deptNo, advisor)

Department Table

department (deptId, name, hod, phone)

2
Mapping ER Diagrams into Relations

Mapping of Regular Entity Types


✓ For each regular (strong) entity type E in the ER schema, create a relation R that includes all the simple
attributes of E.
✓ Choose one of the key attributes of E as primary key for R.
✓ If the chosen key of E is composite, the set of simple attributes that will together form the primary key
of R.
Age

Employee

Name

EmpID
Address
Employee (EmpID, Name, Age, Address)

3
Mapping ER Diagrams into Relations

Mapping of Composite Attributes


✓ When converting to relations parts of the composite attribute. are taken as column names.

Member (memberId, firstname, lastname)

4
Mapping ER Diagrams into Relations

Mapping of Derived Attributes


✓ Derived attributes are not included when making relations.

Person (SSN, Firstname, Lastname, Birthdate,Address)

5
Mapping ER Diagrams into Relations

Mapping of Multivalued Attributes


✓ The multivalued attributes of a relation and the entity key become their own relation.

Person (SSN, Firstname, Lastname, Birthdate,Address)

Hobby(SSN, Hobbyname)

6
Mapping ER Diagrams into Relations

Mapping of 1:1 Relationship


✓ The primary key of the one entity is taken as a foreign key of the other entity.

Staff(emp_no, name, contract_no) or Staff(emp_no, name)

Contract(cont_no, start, end, position, salary) Contract(cont_no, start, end, position, salary, emp_no)

7
Mapping ER Diagrams into Relations

Mapping of 1:M Relationship


✓ The primary key of the “one” side is copied as a foreign key to the “many” side.

Customer(Cus_ID, name, address)

Order(Oder_no, date, no_of_items, Cus_ID)

8
Mapping ER Diagrams into Relations

Mapping of M:M Relationship


✓ A separate relation is created for the relationship having primary keys of other entity types as a
composite key.

Student(Stu_ID, name, address)

Project(Project_ID, name,start_date)

Assign(Stu_ID, Project_ID)
9
Mapping ER Diagrams into Relations

Mapping Weak Entities

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

Member(memberID, firstname, lastname)

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

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)

Lecturer Qualifications(Lecturer ID, Quali_name)


14
Mapping ER Diagrams into Relations
Example 2 Assumptions
Customer can have only one account
Customer can borrow many loans.

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).

Problems without Normalization


Insert, Update, Delete Anomalies

Benefits of Normalized Tables


Normalized tables won’t have duplicate data
Reduce the size of your database
Less data to search
Queries will be faster
16
Database Normalization
Advantages
Reduction of data redundancy within tables:

Reduce data storage space

Reduce inconsistency of data

Reduce update cost

Remove many-to-many relationship

Improve flexibility of the system

17
Database Normalization
Disadvantages

Reduction in efficiency of certain data retrieval as relations may be joined during retrieval.

Increase join

Increase use of indexes: storage (keys)

Increase complexity of the system

18
Database Normalization
Disadvantages

Reduction in efficiency of certain data retrieval as relations may be joined during retrieval.

Increase join

Increase use of indexes: storage (keys)

Increase complexity of the system

19
Database Normalization
Normalization Rules

There are several Normal Forms.

First Normal Form ( 1NF)

Second Normal Form ( 2NF)

Third Normal Form ( 3NF)

20
Database Normalization
First Normal Form ( 1NF)

✓ A relation is in first normal form (1NF) if and only if all attributes are ATOMIC.

i.e. If there are no repeating groups.

If each attribute is a primitive ( integer, real number, character string, but not lists or sets)

ATOMIC data

✓ A little piece of information that can’t or shouldn’t be divided.

✓ ATOMIC data cannot be further divided.

✓ 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)

there must be a primary key for identification

no duplicated rows or columns

each column must have only one value for each row in the table

22
Database Normalization
First Normal Form ( 1NF)

All the entries are atomic and there is

a composite primary key

(employee_id, job_code)

So, the table is in the first normal

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

dependent on the primary key.

✓ If an attribute depends on only part of a primary key, remove it to a separate table.

If entity has a composite primary key

1) Check each attribute against the whole key

2) Remove attribute and partial key to new relation

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

dependent on the primary key.

✓ "Eliminate Columns not Dependent on Key," i.e., if attributes do not contribute to a description of a key,

remove them to a separate table.

29
Database Normalization
Third Normal Form ( 3NF) – Actions Required

1. Check each non-key attribute for dependency against other non-key fields

2. Remove attribute depends on another non key attribute from relation

3. Create new relation comprising the attribute and non-key attribute which it depends on

4. Determine key of new relation

5. Optimize – consider combining tables that have identical primary keys

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

You might also like