normalization in databases
Post on 27-Jan-2015
162 Views
Preview:
DESCRIPTION
TRANSCRIPT
Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
NORMALIZATION IN DATABASES
Subhin P.V111subru@gmail.comwww.facebook.com/111subrutwitter.com/111subruin.linkedin.com/in/Subhin P.V8129076036
MAIN POINTS DISCUSSED
• What normalization is and what role it plays in the database design process
• About the normal forms 1NF, 2NF, 3NF and BCNF• How normal forms can be transformed from lower
normal forms to higher normal forms
ABOUT NORMALIZATION
• Normalization is the process of efficiently organizing data in a database.
• Two goals of normalization process: Eliminating Redundant Data Ensuring data dependencies
• The objective is to isolate data so that changes of a field can be made in just one table and then propagated through the rest of the database using the defined relationships.
Normalization Stages
• 1NF• 2NF• 3NF• Boyce-Codd Normal Form (BCNF or 3.5NF)
Normalization Stages
First Normal Form (1NF)
• The values in each column of a table are atomic (No multi-value attributes allowed).
• Each table has a primary key: minimal set of attributes which can uniquely identify a record
• There are no repeating groups: two columns do not store similar information in the same table.
Second Normal Form (2NF)
• Meet all the requirements of the first normal form.
• Remove subsets of data that apply to multiple rows of a table and place them in separate tables.
• Create relationships between these new tables and their predecessors through the use of foreign keys.
Third Normal Form (3NF)
• Meet all the requirements of the second normal form.
• Every non-prime attribute of R is non-transitively dependent (i.e. directly dependent) on every superkey of R.
• Remove columns that are not dependent upon the primary key.
Boyce-Codd Normal Form
• Meet all the requirements of the third normal form.
• Every determinant must be a candidate key.• Candidate Key:
Any attribute or a set of attributes together that has the eligibility to become a primary key.
TRANSFORMATION FROM UNF TO HIGHER NORMAL FORMS USING AN EXAMPLE
• Example: Institution Having Two departments– Each Department Has 6 Different Students And Some
Courses– Each Student in a department can study more than
one Course – Each course has its course fee.– Periodically, report is generated that contains
information displayed which can be represented in a table as shown in next slide.
Un-normalized Form Example
Problems With The Table
– The table displays data redundancies.
– The table has Multivalued Attributes
– The table entries invite data inconsistencies.
– The data redundancies yield the following anomalies:
• Update anomalies.
• Addition anomalies.
• Deletion anomalies.
Conversion to 1st Normal Form
Conversion To 1st Normal Form
– ADVANTAGES• Each table has at least one minimal set of attributes
which can uniquely identify a record• The values in each column have Single Value
– DISADVANTAGES• Redundant data across multiple rows of the table is still
there• Existence of partial and transitive dependencies
The Dependency diagram– Depicts all dependencies found within given table
structure– Helpful in getting bird’s-eye view of all
relationships among table’s attributes– Makes it less likely that will overlook an important
dependency
Conversion to 2nd Normal Form{Dep No, Dep_name} {Stud no, Stud_name, Stud_DOB, Stud_age}{Dep No, Stud No , Course_name, Course_fee}
Department Details:
Course Details: Student Details:
Conversion to 2nd Normal Form
• Advantages– eliminates redundant data in the table – It includes no partial dependencies:– Create separate tables for sets of values that apply
to multiple records • Disadvantages– The table contains Transitive Dependencies.– Some records depend on attributes other than
the table's primary key
Conversion to 3rd Normal Form
Student Details:
Department Details:
Course Details:
Student course:
{Dep No, Dep_name} , {Stud no, Stud_name,Stud_DOB} , {Dep No, Stud No , Course name} , {Course_name, Course_fee}
Conversion to 3rd Normal Form
• Advantages:– No non-key attribute depends transitively on a
candidate key– All The attributes in a table Depend on a single
primary key
Conversion To BCNF
• A Case where The table is in 3NF but not in BCNF
Example of BCNFfd1 clientNo, interviewDate interviewTime, staffNo, roomNo (Primary Key)fd2 staffNo, interviewDate, interviewTime clientNo (Candidate key)fd3 roomNo, interviewDate, interviewTime clientNo, staffNo (Candidate key)fd4 staffNo, interviewDate roomNo (not a candidate key)
As a consequece the ClientInterview relation may suffer from update anomalies.For example, two tuples have to be updated if the roomNo need be changed for staffNo SG5 on the 13-May-02.
ClientNo interviewDate interviewTime staffNo roomNoCR76 13-May-02 10.30 SG5 G101
CR76 13-May-02 12.00 SG5 G101CR74 13-May-02 12.00 SG37 G102CR56 1-Jul-02 10.30 SG5 G102
ClientInterview
Example of BCNF(2)
To transform the ClientInterview relation to BCNF, we must remove the violating functional dependency by creating two new relations called Interview and SatffRoom as shown below,
Interview (clientNo, interviewDate, interviewTime, staffNo)StaffRoom(staffNo, interviewDate, roomNo)
ClientNo interviewDate interviewTime staffNoCR76 13-May-02 10.30 SG5
CR76 13-May-02 12.00 SG5CR74 13-May-02 12.00 SG37CR56 1-Jul-02 10.30 SG5
staffNo interviewDate roomNoSG5 13-May-02 G101
SG37 13-May-02 G102SG5 1-Jul-02 G102
Interview
StaffRoom
THANKS
If this presentation helped you, please visit our page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
top related