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

Week 3 Dbms

The document discusses database normalization and different normal forms including 1NF, 2NF, 3NF, BCNF. It provides examples of denormalizing a sample movie rental database to move it from 1NF to 2NF to 3NF through table splitting and introducing foreign keys. The goal of normalization is to minimize redundancy and inconsistencies in the database.

Uploaded by

Rajesh Jupaka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Week 3 Dbms

The document discusses database normalization and different normal forms including 1NF, 2NF, 3NF, BCNF. It provides examples of denormalizing a sample movie rental database to move it from 1NF to 2NF to 3NF through table splitting and introducing foreign keys. The goal of normalization is to minimize redundancy and inconsistencies in the database.

Uploaded by

Rajesh Jupaka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Normalization:It is a process of analyzing the given relation schemas based on

theirFunctional Dependencies (FDS) and primary key to achieve the properties


Minimizing redundancy
Minimizing insertion, deletion and update anomalies.

Functional Dependencies:A Functional dependency is denoted by X Y between two


sets of attributes X and Y that are subsets of R specifies a constraint on the possible tuple
that can form a relation state r of R. The constraint is for any two tuples t1 and t2 in r if
t1[X] = t2[X] then they have t1[Y] = t2[Y]. This means the value of X component of a tuple
uniquely determines the value of component Y.

Normal forms:The process of normalization is based on the concept of normal forms,Each


& every normal form has its own set of properties & Constraints. A table / relation is said to
be in normal form if it satisfies all the properties of that normal form.

1 NF :The domain of attribute must include only atomic (simple, indivisible) values.

2 NF:A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A inR is
fully functionally dependent on primary key.

3 NF:A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the
following is true

X is a Super-key of R.
A is a prime attribute of R.

In other words, if every non prime attribute is non-transitively dependent on primary key.

4 NF:A relation schema R is said to be in 4NF if for every multi-valued dependency X


Y that holds over R, one of following is true

X is subset or equal to (or) XY = R.


X is a super key.

5 NF:A Relation schema R is said to be 5NF if for every join dependency {R1, R2...Rn}
that holds R, one the following is true
2. Ri = R for some i.
3. The join dependency is implied by the set of FD, over R in which the left side is key of R.
4. BCNF (Boyce-Codd Normal Form):A relation schema R is in BCNF if it is in 3NFand
satisfies an additional constraint that for every FD X A, X must be a candidate key.

5. Database Normalization Examples -


6. Assume a video library maintains a database of movies rented out. Without any
normalization, all information is stored in one table as shown below.
7.

Here you see Movies Rented column has multiple values.


Database Normal Forms
Now let's move into 1st Normal Forms
1NF (First Normal Form) Rules
 Each table cell should contain a single value.
 Each record needs to be unique.
The above table in 1NF-
1NF Example
2NF (Second Normal Form) Rules
 Rule 1- Be in 1NF
 Rule 2- Single Column Primary Key
It is clear that we can't move forward to make our simple database in 2nd Normalization form
unless we partition the table above.

We have divided our 1NF table into two tables viz. Table 1 and Table2. Table 1 contains
member information. Table 2 contains information on movies rented.
We have introduced a new column called Membership_id which is the primary key for table
1. Records can be uniquely identified in Table 1 using membership id
Database - Foreign Key
In Table 2, Membership_ID is the Foreign Key

Foreign Key references the 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 the Primary key, they do not have to be
unique. Most often they aren't
 Foreign keys can be null even though primary
keys can not
Why do you need a foreign key?
Suppose, a novice inserts a record in Table B such as
You will only be able to insert values into your foreign key that exist in the unique key in the
parent table. This helps in referential integrity.
The above problem can be overcome by declaring membership id from Table2 as foreign
key of membership id from Table1
Now, if somebody tries to insert a value in the membership id field that does not exist in the
parent table, an error will be shown!
What are transitive functional dependencies?
A transitive functional dependency is when changing a non-key column, might cause any of
the other non-key columns to change
Consider the table 1. Changing the non-key column Full Name may change Salutation.

Let's move into 3NF


3NF (Third Normal Form) Rules
 Rule 1- Be in 2NF
 Rule 2- Has no transitive functional dependencies
To move our 2NF table into 3NF, we again need to again divide our table.
3NF Example

We have again divided our tables and created a new table which stores Salutations.
There are no transitive functional dependencies, and hence our table is in 3NF
In Table 3 Salutation ID is primary key, and in Table 1 Salutation ID is foreign to primary
key in Table 3
Now our little example is at a level that cannot further be decomposed to attain higher forms
of normalization. In fact, it is already in higher normalization forms. Separate efforts for
moving into next levels of normalizing data are normally needed in complex
databases. However, we will be discussing next levels of normalizations in brief
in the following.
Boyce-Codd Normal Form (BCNF)
Even when a database is in 3rd Normal Form, still there would be anomalies
resulted if it has more than one Candidate Key.
Sometimes is BCNF is also referred as 3.5

You might also like