Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

DBMS Normalization

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)
15 views

DBMS Normalization

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/ 12

SQL -Normalization

- Vaidehi Raval
Database Normalization

• Normalization
• First Normal Form (1 NF)
• Primary Key
• Composite Key
• Foreign Key
• Second Normal Form (2 NF)
• What is a Transitive Functional Dependency?
• Third Normal Form (3 NF)

Normalization
2
Database Normalization

Normalization
• Normalization is a database design technique which organizes tables in a manner that
reduces redundancy and dependency of data.
• It divides larger tables to smaller tables and links them using relationships.
• Theory of Normalization is still being developed further. For example there are
discussions even on 6th Normal Form. But in most practical applications normalization
achieves its best in 3rd Normal Form. The evolution of Normalization theories is
illustrated below-

Normalization
3
Database Normalization

Example: Consider a healthcare system which tracks the visits of patients.

Patient Name Salutation Gender Marital Status Visit Purpose Visit Fees Visit Date

Janet Jones Ms. Female Single Dental 200, 500 12-Jan-2012,


Consultation, 15-Jan-2012
Root Canal
Robert Phil Mr. Male Single CT - Chest, CBC, 250, 90,140 14-Dec-2011,
ESR 12-Dec-2011,
13-Dec-2011
Josh Mathews Mr. Male Married Endoscopy 500 11-Feb-2012

Janet Jones Mrs. Female Married Cardiology 210, 60 22-Jan-2012,


Consultation, X- 21-Jan-2012
Ray

Here you see Visit Purpose, Visit Fees and Visit Date column have multiple values.

Normalization
4
Database Normalization
First Normal Form (1 NF)
No Repeating Elements or Groups of Elements
• Each table cell should contain single value
• Each record needs to be unique

Patient Name Salutation Gender Marital Status Visit Purpose Visit Fees Visit Date
Janet Jones Ms. Female Single Dental Consultation 200 12-Jan-2012
Janet Jones Ms. Female Single Root Canal 500 15-Jan-2012
Robert Phil Mr. Male Single CT - Chest 250 14-Dec-2011
Robert Phil Mr. Male Single CBC 90 12-Dec-2011
Robert Phil Mr. Male Single ESR 140 13-Dec-2011
Josh Mathews Mr. Male Married Endoscopy 500 11-Feb-2012
Janet Jones Mrs. Female Married X-Ray 60 21-Jan-2012
Janet Jones Mrs. Female Married Cardiology Consultation 210 22-Jan-2012

• Now the data is in 1 NF.


• But as we can see for each patient visit there is a redundancy of data in Patient
Name, Salutation, Gender and Marital Status for the patients who have multiple
Visit Purposes.

Normalization
5
Database Normalization

Primary Key

•A primary key is a value used to uniquely identify a record in a table.


•A primary key could be a single column or combination of multiple
columns
•A primary key cannot be NULL
•A primary key value must be unique
•The primary key must be given a value when a new record is inserted

Tip: Columns in a table that are NOT used to uniquely identify a record are called non-key
columns
Normalization
6
Database Normalization

Composite Key

• A composite key is a primary key composed of multiple columns used to identify a


record uniquely
• In our database, we have two people with the same name Janet Jones they are
different as one is single and other married.

Composite Key: Patient Name + Marital Status

Patient Name Salutation Gender Marital Status Visit Purpose Visit Fees Visit Date
Janet Jones Ms. Female Single Dental 200, 500 12-Jan-2012,
Consultation, 15-Jan-2012
Root Canal
Janet Jones Mrs. Female Married Cardiology 210, 60 22-Jan-2012,
Consultation, X- 21-Jan-2012
Ray
Robert Phil Mr. Male Single CT - Chest, CBC, 250, 90,140 14-Dec-2011,
ESR 12-Dec-2011,
13-Dec-2011

• Names of patients are common, hence a composite key (composition of Name and
Maritial Status column) is needed to uniquely identify a record

Normalization 7
Database Normalization

Foreign Key

• Foreign Key references primary key of another Table. It


helps connect your Tables
• A foreign key can have a different name from its primary
key
• It ensures rows in one table have corresponding rows in
another
• Unlike Primary key they do not have to be unique. Most
often they aren’t
• Foreign keys can be null even though primary keys
cannot

Normalization
8
Database Normalization
Second Normal Form (2 NF)

• Must be in 1 NF
• The non key columns must not depend on part of composite primary key, hence
implement a single column primary key
PK Patient ID Patient Name Salutation Gender Marital Status • We have divided our 1NF
1 Janet Jones Ms. Female Single
table into two tables viz.
Patient and PatientVisit.
2 Robert Phil Mr. Male Single
3 Josh Mathews Mr. Male Married
• Introduced a new column
called Patient ID which is
4 Janet Jones Mrs. Female Married
the primary key for Patient
FK table. Records can be
Patient ID Visit Purpose Visit Fees Visit Date
uniquely identified using
1 Dental Consultation 200 12-Jan-2012
Patient ID.
1 Root Canal 500 15-Jan-2012
• Patient ID is used as a
2 CT - Chest 250 14-Dec-2011
Foreign key in PatientVisit
2 CBC 90 12-Dec-2011 table
2 ESR 140 13-Dec-2011
3 Endoscopy 500 11-Feb-2012
4 X-Ray 60 21-Jan-2012
4 Cardiology Consultation 210 22-Jan-2012

Normalization 9
Database Normalization

Transitive Functional Dependency

• Transitive functional dependency is when a non-key column is dependent on the


other non-key columns to change
• In other words, every non key column must be dependent on primary key

A change in Marital Status may change Salutation

Patient ID Patient Name Salutation Gender Marital Status


1 Janet Jones Ms. Female Single
2 Robert Phil Mr. Male Single
3 Josh Mathews Mr. Male Married
4 Janet Jones Mrs. Female Married

• In above example, a change in a non key column name may cause a change in
other non key column Salutation

Normalization
10
Database Normalization
Third Normal Form (3 NF)

FK
PK PK Sal ID Salutation
Patient ID Patient Name Sal ID Gender Marital Status
1 Janet Jones 1 Female Single 1 Ms.
2 Robert Phil 2 Male Single 2 Mr.
3 Josh Mathews 2 Male Married 3 Mrs.
4 Janet Jones 3 Female Married 4 Dr.

FK Patient ID Visit Purpose Visit Fees Visit Date • Must be in 2 NF


1 Dental Consultation 200 12-Jan-2012 • Has no functional
1 Root Canal 500 15-Jan-2012 transitive
2 CT - Chest 250 14-Dec-2011 dependencies
2 CBC 90 12-Dec-2011 • Achieved by
2 ESR 140 13-Dec-2011 further breaking
3 Endoscopy 500 11-Feb-2012 down the data in
4 X-Ray 60 21-Jan-2012 multiple tables
4 Cardiology Consultation 210 22-Jan-2012

Normalization
11
Thank You

- Vaidehi Raval
12

You might also like