Вы находитесь на странице: 1из 35

-1-

UNIT - 2
DATA MODELING & NORMALIZATION

E-R models

The Entity-Relationship (E-R) model is a detailed logical representation of data for an


organisation. That shows graphical representation of entities, attributes and their
relationships. It is based on the view of real world that consists of basic objects called
entities, and relationships among entities.
An E-R model is expressed by ER-model diagrams. An ER diagram is a graphical
representation of ER-model.

E-R-model notations:

ENTITY TYPES:

Strong entity type

Weak entity type

Associative entity type

ATTRIBUTES:
To represent simple and
single values attribute

Multi valued attribute

Derived Attribute

Composite attribute

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


-2-
RELATIONSHIP:

Relation ship

Identifying relation ship (to represent


relation ship between strong and weak
entity)

TYPES OF RELATIONS BASED ON DEGREE:

Binary relation ship


2)

1)Unary relation ship

3)Ternary relation ship

TYPES OF RELATIONSHIPS BASED ON CARDINALITIES:

1) Exactly one

2) Exactly many

3) Optional one

4) Optional many

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


-3-
E-R Model constructs (or) components of e-r model

The E-R model consists of 3 components.


They are:
1. Entities
2. Attributes
3. Relationships

ENTITIES:
An entity is nothing but a person, a place, an object an event, a concept and so on.
For example:
Person ->customer, student, employee…..
Place -> repository, warehouse, store…..
Concept -> course, account ….
Object -> machine, building …..
Event -> reservation, sale, with drawl…

Entity or Entity Instance:

The fundamental unit in any data model is the entity. An entity is a person, object,
place, Thing or event about which the organisation wishes to maintain data. In General we
will say “any thing is said to be an Entity but it must have some attributes “. We will use
rectangle symbol to define entity in database environment.

For example
PERSON PRODUCT ENPLOYEE COMPUTER

Entity Type

An entity type or entity set is a collection of entities that share a common property.
Entity type name is always singular and is represented in capital letters. For the names is an
entity type. In an E-R diagram, entity name is placed in side the rectangular box represented
in entity type.
For example:

PERSON DEPT ENPLOYEE COURSE

For example: Entity type = STUDENT


Attributes = Roll_no , Name, Course, Marks

The entity instances of STUDENT entity type are:


1001 XYZ BSC 700
1002 ABC BCOM 560
: : : :
: : : : and so on ..

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


-4-
Types of Entities:

Entities are different types. They are

• Strong Entity
• Week Entity
• Associative Entity

Strong Entity:
In an organisation most of the entity types are classified as strong entity types. A
strong entity is an entity type, whose existence dose not depends upon another entity type. If
is also represented by using rectangle symbol.
For example.
STUDENT EMPLOYEE PART

Note:- Generally an entity types has identifier attribute.

Weak Entity:
A weak entity is an entity type .Whose existence depends upon another entity type .A
weak entity type has no business meaning in the E-R diagram without the entity on which it
depends. The entity type on which the weak entity type depends is called the “identifying
owner” (or) simply called “owner”. A weak entity does not have an identifier attribute.
Generally it has an attribute that is called as “partial identifier attribute”.
The weak entities are represented by using “double lined rectangle”. The
relationship b/w weak entity and its owner is called “identifying relationship”. That is
represented by “double lined diamond symbol”.

Dob Address Trandate


Age

Eno Dname
Salary Amount

EMPLOYEE Has DEPARTMENT

Associative entity type:


An associative entity is nothing but an entity with relationship. It is represented by
using the following symbol.

Start_date

Works_f DEPARTMENT
EMPLOYEE or

2. Attributes:
SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .
-5-
Each entity type is associated with a set of attributes. An attribute is nothing but a
property (or) a characteristic of an entity type. The attributes are represented by giving a name
with in the “ellipse symbol”. If an attribute name consists of more than one word, we can use
underscore symbol to connect there words and we can start each word with a capital letter
.For example
Ename Age

Eno
Salary

EMPLOYEE

Types of attributes
The attribute types are classified as follows:
1. Simple attribute
2. Composite attributes
3. Single-valued attributes
4. Multi-valued attributes
5. Store derived attributes
6. Simple derived attributes
7. Composite identifier attributes

1. Simple attribute:-The simple attribute is attribute, cannot be derived into smaller


components. These are represented an E-R diagram by using ellipse symbol.
For example:
vname color

Vid
cost

VEHICLE

Where vehicle_Id, model, colour, speed are the simple attributes.

2. Composite attributes:-A composite attribute is an attribute that can be broken down


Into no. of components .The composite attributes are represented by using the followings.
For example:-

Sno Sname
Day

STUDENT Month
Dob
Year

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


-6-
3. Single-valued attributes:- Simple –valued attributes is an attribute, that may take one value
for a given entity instance .This is represented by an ellipse symbol.
For example vname color

Vid cost

VEHICLE

Here vehicle_id, model, color, speed and cost are the simple and single valued attributes.

4. Multi valued attributes:-Multi valued attributes is an attribute that may take more than one
value. For a given entity instance .The multi valued attributes are represented by a double
lined ellipse symbol
For example: Sno Sname

Sno Sname OR
STUDENT

Skills
STUDENT
Skills

5. Stored derived attributes:- Some attribute values can be calculate (or) derived from other
related attribute values ,values, that are stored in the database . It is called as stored
attribute.
A derived attributed is an attribute, that is derived from other related attributes. These
are represented by darted ellipse symbol
For example:-
Sno Sname

M2

STUDENT
M1
Total M3

6. Simple identifier attribute:-An identifier is an attribute (or) combination of attributes that


uniquely identifies individual instances of an entity type. It is represented by using ellipse
symbol, inside place single underlined
For example:
Accountnn
o

Account

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


-7-
Composite identifier attribute:-
An identifier ,that onsists of a composite attribute is called the composite
identifiers attribute. It is represented by ellipse symbol,inside with double
underlined.
Flight_no
No_of_seats

fare
Flight id

Flight

Derived attribute A simple attribute is composed of single component with an


independent existence. For example, empno, job, salary etc.

Composite Attribute It is composed of multiple attributes, each with an independent


existence. For example, the Address attribute can be composed of
components like Street name, Area, City, PINcode and so on.
Single-valued Attribute A single-valued attribute holds a single value for a single entity. For
example, empno, job, salary etc. because they hold only one value for
each record.
Multi-valued Attribute A multi-valued attribute holds multiple values for a single entity. For
example, the Hobby attribute of a student entity can have multiple
values like reading, music, movies and so on.
Derived Attribute The value for this type of attribute is derived from the values of other
related attributes. For example, HRA attribute is derived from the
Salary attribute.

For example

Depd_no Name
Ename job

Employee dependent
Eid

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .

Dateof birth
-8-

Relationships:
A relationship is an association between the instances of one or more entity types. In
E-R diagram the relationships are represented by a diamond symbol

In case of relationship between strong and weak entities we can use the diamond
symbol with double lines.

Types of relationships:

Based on the degree, cardinalities, the relationships are mainly classified into two
types, they are: 1) unary relationships
2) binary relationships
3) ternary relationships

Degree of the relationship: The degree of relationship is the no.of entity types that are
participated in a relationship.

Unary relationship: A unary relationship is a relationship between the instances of a


single entity type. The degree of unary relationship is one for example.

Employee
Manage
s

In the above diagram “manages” is shown as one to many relationships between


instances of an employee entity type. Because one employee can manage many
activities.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


-9-
Binary Relationship:
A relationship between the instances of two entities is called a binary
relationship. The following diagram explains the relationship between
two entities.

Binary relationship:

Employee Assigned Department

One –to – one Relationship

The following diagrams show one-to-many , many-to-many


relationships in the binary relationship.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 10 -

Product List contains Product

One –to Many Relationships

Is
Student registered Course
for

Many – to – Many Relationships

Ternary relationships or high relationships:


A relationship that exists among different entities of the data base is
called ternary relationship or high degree relationship. The following
figure shows the ternary relationship among different entities.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 11 -

Vendor Ware house


Supplies

Part

Many – to – Many Relationship

Developing an ER diagram:

The process of data base design is an repeated process. The ER


modeling
usually involves the following activities :

1. Create a detailed description of the organization and its


requirements
2. Identify the business rules based on the description of
operations.
3. Identify the main entities and relationships from business rules.
4. Develop the Initial Entity relationship diagram.
5. Identify the attributes and primary keys that appropriately
describe the entities.
6. Revise and Review the Entity Relationship Diagram(ERD).

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 12 -
During the design process the database designer does not depend
simply on interviews to help define entities, rather the designer
takes the day to day transactions into consideration.
Take the following case study to develop a design based on ER
diagram.
Case study:
A college, we can name City College is divided into several
departments, dept of business, department of arts, department of
sciences etc. Each department is administered by Dean or Head of
the Department. We must show the relationships among different
departments of the College using and in other words we must model
the college.

Each department is administered by the Head or Dean and he /she


must be a professor:
The following table shows the components or entities and their
relationships of this case study
Entity Relationship Connectivity Entity

School Operates 1:M Department

Department Has 1:M Student

Department Employs 1:M Professor

Department Offers 1:M Course

Course Generates 1:M Class

Professor Is dean of 1:1 School

Professor Chairs 1:1 Department

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 13 -
Professor Teaches 1:M Class

Professor Advises 1:M Student

Student Enrolls in 1:M Class

Building Contains 1:M Room

Room Is used for 1:M Class

Note : enroll is the composite entity that implements the relationship


“student” enrolls “class”.

E-R DIAGRAM CONVENTIONS (RULES):

The following are the rules for representing the entities and attributes in the E-R
diagram.

1. The entities are represented by a rectangular box with the name of the entity in the box
in uppercase letters

STUDENT EMPLOYEE PRODUCT

2. An attribute is shown as ellipse and labelled with the attribute name in lowercase
letters

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 14 -

Salary Joindate Empname

3. The primary keys (key attributes) are underlined

Empno Rollno Itemcode

4. The attributes are connected using lines to the entities and if the attribute is simple or
single valued, a single line is used.

Empnam
Empno
e

EMPLOYEE

Job Salary

5. If the attribute is derived, a dotted line is used

Empno Salary Empno Salary

(OR)
EMPLOYEE EMPLOYEE

hra hra

6. If the attribute is multi valued then double lines are used

Empno Salary Empno Salary

(OR)
EMPLOYEE EMPLOYEE

Hobby Hobby

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 15 -
7. If the attribute is composite, its component attributes are shown as ellipses and
connected to the composite attribute

Empnam
Empno
e Street

EMPLOYEE City
Address
Pincode

3 . What are the Symbols of E/R model ?

The entity relation ship model is a detailed graphical representation of the data for an
organization . An E-R model is normally expressed through E-R diagrams, which is a
graphical representation of an E-R model. The E-R model can express the information in
terms of graphical pictures i.e Entities, Attributes , and Relations .The basic notation for an
E-R diagram is as follows.

Strong Entity Type

Weak Entity Type

Associative Entity Type

Attribute

Multi valued Attribute

Derived Attributes

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 16 -
Relation ships

Identifying Relationship.

4.What is Relation Ship ? Expalin the Degrees of Relationships ?

RELATIONSHIPS

A relationship is an association between entities. Usually the relationship is identified


by a name which is verbal and descriptive. Relationships are represented by diamond shaped
symbols with the relationship name inside the diamond. The two sides of the diamond are
connected to the entities.

For example, the following E-R diagram shows the relationship between the entities
PUBLISHER and BOOK

Publishe
PUBLISHER BOOK
s

Degree of Relationship
The degree of relationship indicates the number of associated entities. There are
mainly 3 types of relationship degree in E-R model. They are
 Unary relationship
 Binary relationship
 Ternary relationship

Unary Relationship
A unary relationship exists when an association is maintained within a single entity.
Example:

EMPLOYEE

Manage
s

The above relationship states that an employee manages another employee.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 17 -

Binary Relationship:
When two entities are associated with a relationship then it is called binary
relationship. It is the most common relationship that appears in E-R modelling.
Example:

EMPLOYEE Joins DEPT

The above relationship states that an employee joins in a department.

Ternary Relationship:
When three entities are associated with a common relationship then it is called
ternary relationship. Example-2:
The above relationship states that a vendor
Example-1:
sells a product to the customer.
PRODUCT
SUBJECT

Teach VENDOR Sells CUSTOMER


TEACHER STUDENT
es

The above relationship states that a teacher


teaches a subject to a student.

Relationship cordinalities:-
A cardinality constraint specifies the no.of instances of one entity type ,can be associated with each
instance of another entity type .Based on cardinality, the relationships can be classified into different
types .They are.
One -to-one Relationship:

In this type, an entity in X is associated with at most one entity in Y, and an entity in Y
is associated with at most one entity in X.
Example:

1 1
EMPLOYEE Joins DEPT

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 18 -
The above relationship indicates that one employee has to join in only one department.

One-to-many Relationship:
In this type, an entity in X is associated with any number of entities in Y. However, an
entity in Y is associated with at most one entity in X.
Eg:

1 N
DEPT Has EMPLOYEE

The above relationship indicates that one department has many employees.

Many-to-one Relationship:

In this type, an entity in X is associated with at most one entity in Y. However, an


entity in Y can be associated with any number of entities in X.
Eg:

N 1
EMPLOYEE Join DEPT

The above relationship indicates that many employees can join in only one department.

Many-to-many Relationship:

In this type, an entity in X is associated with any number of entities in Y and an entity
in Y is associated with any number of entities in X.
Eg:

N N
TEACHER Teach STUDENT

The above relationship connectivity indicates that many teachers teach many students.

5. What is Cardinality constraints ? Explain

The cardinality expresses the specific number of entity occurrences associated with
one occurrence of the related entity. The actual number of associated entities is governed by
the business rules. The cardinality is indicated by placing the appropriate numbers beside the
entities.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 19 -
For example, the company policy does not allow more than 100 employees in a department.
Therefore the cardinality rule governing the DEPARTMENT-EMPLOYEE relationship is
expressed as “One department can have a maximum of 100 employees. But one employee can
join only in one department.” This can be shown as:

1 N
DEPT Has EMPLOYEE
(1, 100) (1, 1)

Participation of Relationship

The participation specifies that the relationship exists between entities either totally or
partially. The participation can also be known as mandatory or optional.
The participation is mandatory (total) if an entity’s existence requires the existence of
an associated entity in a particular relationship.
The participation is optional (partial) if the occurrence of one entity does not require
the occurrence of another corresponding entity in a relationship. An optional entity is shown
by drawing a small circle on the side of the optional entity.

Example:

1 1
STUDENT Takes BOOK

In the above STUDENT-BOOK relationship, the STUDENT entity is mandatory,


where as BOOK entity is optional. It specifies that the student may or may not take a book.

Dependency

The dependency specifies whether the entity types are strong or weak.
Strong Entity:
If an entity type is not existence dependent on some other entity then it is called strong entity
type. In other words, an entity set that has a primary key is called strong entity type. The
strong entities are also known as parent, owner or dominant entities.
Weak Entity:
If an entity type is existence dependent on some other entity then it is called weak entity type.
In other words, if an entity set may not have sufficient attributes to form a primary key then it
is known as weak entity type. Weak entities are also known as child, dependent or
subordinate entities. The weak entities are represented by a double lined rectangle.
Weak Relationship:
The relationship between a weak entity and strong entity is called weak relationship. This can
be represented as double lined diamond symbol.
Example:

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 20 -

Custname Trantype Trandate


Opendate

Accno Accno
Balance Amount

CUSTOMER Makes TRANSACTION

Attributes on Relationships:
Attributes may be associated with a many-to-many or one-to-one relationship.
For example, if the students are completing their course, the organisation wishes to
record the date on which the student completes the course. Hence the attribute
date_completed can be represented as shown below:
Studname
Joinndate Date_completed Courseid Coursename
Studid
Address

N Complete N
STUDENT COURSE
s

In the above diagram the attribute date_completed is an attribute of relationship rather


than the attribute of entities. So the date_completed attribute is connected to the relationship
symbol.
Suppose, if the organisation also decided to issue a certificate whenever the student
completes the course, the certificate number must also be recorded along with date_completed
attribute. This can be shown as below:
Studname CertNum
Joinndate Courseid Coursename
Date_completed
Studid
Address

N Complete N
STUDENT COURSE
s

If there are more than one attribute is present on a relationship then it is suggested to
the designer to treat the relationship as an entity type. This can be achieved through composite
or associative entity.

Composite or Associative Entity:


A composite entity is an entity type that associates one or more entity types and
contains attributes that are separate to the relationship between those entities.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 21 -
A composite entity is used to convert many-to-many relationships into one-to-many
relationships. The composite entity is composed of the primary keys of each of the entities to
be connected. The associative entity is represented by a diamond shape within a rectangle.
While converting relationship into composite entity, the relationship name is converted
into an entity name i.e. singular noun. The relationship notation i.e. many (M or N) must be
placed beside the composite entity rather than at each entity type. This can be represented as
shown below:

CertNumber Date_completed
Stu
dId

eid
urs
Co
1 N N 1
STUDENT COMPLETE COURSE

Address StudId
Coursename Courseid
Joinndate Studname

E-R DIAGRAMS (ERDs)

E-R diagram also called data schema map or data map is another means of capturing
the data and the transactions of an organization. The E-R diagram collects the entities, their
attributes and the relationships between the entities. The E-R diagram pictorially represents
the interrelationships of the database schema. The major components of an ERD are entities,
attributes, relationships and cardinality of the association.

******

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 22 -

ENHANCED ENTITY RELATION SHIP

The enhanced entity relationship model is the model, extended from an e-r model by
specifying super type and subtype relationships, constraints on super type and subtype
relationships and so on.

Representing the Super type / Sub type relation ship:


The e-r model is extended by specifying super type and subtype relationships called
EER model. Where super type is a generic entity type that has a relationship with one (or)
more sub types. A subtype is a sub grouping of entities in an entity type and that should be
meaningful to the organisation

The General format of Super type and Sub type relation ship is as follows.
Attributes those are common to
all
Subtypes

SUPER TYPE

SUB TYPE SUB TYPE

Attributes those
Attributes those
are unique to a
are unique to a
particular sub
particular sub type
type

In the above basic notation a line is extended from the super


type to the circle for example ..,.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 23 -
SUPER TYPE AND SUB TYPE RELATION SHIP

P_id
P_name P_address

PATIENT

IN_PATIENT OUT_PATIENT

Next_consulting_
Dischar Room_no date
g_date

7. What is EER model? How can you represent the Generalization and
Specialization by using the EER model?

A) EER model stands for Enhanced Entity Relation ship model. It is nothing but the extension
of Entity Relation ship model. It is also said to be a Extended Entity Relationship model and
E2E model. It includes all modelling concepts of basic E-R and additional concepts of
Super class / Sub classes, specialization/generalization, and categories and attributes
inheritance.

In Enhanced Entity Relationship model for representing the super type and sub type
relation ship, the Organizations have used two techniques i.e.

⇒ Generalisation
⇒ Specialisation

These techniques are used to develop the super /sub type relation ships depending on
the nature of the problem and structure of the environment etc.

GENERALISATION: Generalisation is a process defining a more general entity type


for

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 24 -
a set of specialised entity types . .So Generalisation follows
the
Bottom-up-approach to define the super type /sub type relation
Ship. It is also a reverse process of Specialisation process.

In this process several classes with common features are


generalized into Super Classes and original classes become
its Sub classes .

For example.. CAR, TRUCK generalized into VEHICLE ;


both CAR and TRUCK become Sub Class and VEHILCLE as a
Super Class .

Alternatively we can say VEHICLE as a generalization of CAR


and TRUCK .

Vid V_type
Vid V_type Price

Price TRUCK
CAR

Capacit Shape
No_of_ Color y
seats

Note that the above two entity types have several attributes in common .in addition each
entity type has one or more unique attributes . in this situation, generalization allows us to
group entity types along with their common attributes and at the same time specific attributes
that are particular to each sub type.

Once we generalize the above said Entities.., the diagram is as follows

V_type
Vid Price

VEHICLE

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 25 -

CAR TRUCK

No_of_
Color Shape Capacity
seats

Generalization of super type and sub type

SPECILIAZATION : Specialisation is the process of defining one or more subtypes from a


general
entity type and forming Super type / Sub type relation ship . Here each sub
type is formed with one or more unique attributes . So , specialisation is top
down process.

It is a process defining a set of sub classes of a super classes . The set


of
sub class based upon some distinguishing characteristics of the entities
in
the super class .The super class /sub class relation ship of
specialisation
can be diagrammatically represented in EER diagrams .

For example , consider an Entity type PATIENT , he has several


Attributes like P_id , P_name,P_address, Room_no , Dis_charge_date,
Next_consult_data ….etc…

P_Address
Room_no
Dis_charge_
P_name data

P_id PATIENT Next_consult_


data

In the above example , there are two possible sources for patients. they
are
In_patients and Out_patients .they have their own unique attributes
which
are unique to that entities .

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 26 -

for example : Room_no and Dis_charge_date for IN_PATIENT


and
Next_consult_date for OUT_PATIENT .consider the
following diagram

P_name
P_id P_Address

PATIENT

OUT_PATIENT
IN_PATIENT

DIS_CHARGE
_DATE
NEXT_CONSULT_DAT
E
ROOM_NO

Specialization of super type /sub type

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 27 -

NORMALISATION

Normalisation is the initial process of building database structures to store data. It is


the method for deciding which attributes should be grouped together in a relation. It is the
process of defining the relations to remove the amount of redundancy.

Functional Dependency:
It is a constraint between two attributes or two sets of attributes. For any relation R, if
the functionally dependency is AB, then B is an attribute that is functionally dependent on
attribute A.

For example, consider the relation, Student (stud_id, studname, address, course,
date_completed)
The functional dependencies in the above relation are
Stud_id  studname, address
Stud_id, course  date_completed
Some other examples are
Empno  empname, job, address
Prod_id  prod_name, price

Determinant:
The attribute on the left hand side of the arrow in a functional dependency is known as
determinant. In the above examples, stud_id, empno and prod_id are called determinants.

Dependent:
The attribute on the right hand side of the arrow in a functional dependency is known
as dependent. In the above examples studname, address, job, price are called dependents.

Candidate Keys:
A candidate key is an attribute or combination of attributes that uniquely identify a
record in a relation. It must satisfy the following properties:
1. Unique Identification
2. Non-redundancy
For example, consider the relation
Student (stud_id, studname, address, course)
Stud_id is the determinant in the above relation. All the remaining attributes are
functionally dependent on stud_id. Hence it is called candidate key. The functional
dependency can be shown graphically in the following way:

Stud-id Studname address course

Consider another example as,


Student (stud_id, studname, address, course, date_completed)

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 28 -
The two functional dependencies are
Stud_id  studname, address
Stud_id, course  date_completed
They can be shown graphically as

Stud-id Course Studname Address Date_completed

In the above relation, stud_id and course jointly called candidate key.

NORMAL FORMS
A set of rules to implement normalisation is called normal form. The normal forms are
classified as basic normal forms and advanced normal forms. These are as follows:

NORMAL FORMS

BASIC NORMAL FORMS ADVANCED NORMAL FORMS

Boyce-Codd Normal Form (BCNF)


First Normal Form (1NF) Fourth Normal Form (4NF)
Second Normal Form (2NF) Fifth Normal Form (5NF)
Third Normal Form (3NF) Domain Key Normal Form (DKNF)

First Normal Form (1NF):


A relation is in first normal form if it contains no multi-valued attributes. According to
the definition of a relation, there must be a single value at the intersection of each row and
column. For example, consider the following relation:

STUDENT
Stud-id Studname Address Course Date_completed
101 ABC DELHI C 12/5/2005
C++ 17/9/2005
102 XYZ MUMBAI MSOFFICE 20/5/2005
VB 28/10/2005

The above relation is not in first normal form. Because it is containing two multi-
valued attributes namely course and date_completed. For removing these attributes, we have
to fill the vacant cells with relevant data. Thus the above relation becomes as follows:

STUDENT
Stud-id Studname Address Course Date_completed

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 29 -
101 ABC DELHI C 12/5/2005
101 ABC DELHI C++ 17/9/2005
102 XYZ MUMBAI MSOFFICE 20/5/2005
102 XYZ MUMBAI VB 28/10/2005

Second Normal Form (2NF):


A relation is said to be in second normal form, if it contains the following properties.
1. It must be in first normal form
2. It must not contain the partial functional dependencies

Partial Functional Dependency: The functional dependency in which the determinant is a


part of the candidate key is called the partial functional dependency.
For example, consider the following relation

STUDENT
Stud-id Studname Address Course Date_completed
101 ABC 12/20, DELHI C 12/5/2005
101 ABC 12/20, DELHI C++ 17/9/2005
102 XYZ 23/110, MUMBAI MSOFFICE 20/5/2005
102 XYZ 23/110, MUMBAI VB 28/10/2005

The two FDs are stud_id  studname, address


Stud_id, course  date_completed

The candidate key for the above relation is the combination of stud_id and course. In the
above two FDs, the first one is called the partial functional dependency, because the
determinant stud_id is a part of the candidate key stud_id and course. Because of these partial
functional dependencies, the following inconsistencies may result:

i. Insertion Anomaly: If a student is completed any course then we have to insert all the
details of that student for every course. Thus there is wastage of
memory.
ii. Deletion Anomaly: If we delete the student details then the related course details are
also removed.
iii. Updation Anomaly: A student may complete many courses. Hence his data is
repeated for each course. So, modification of one student details
may result modification in many rows. Thus there is wastage of
time.

To overcome all these anomalies the above relation can be divided in the following way:
STUDENT (stud-id, studname, address)
STUD_COURSE (stud-id, course, date_completed)

Stud-id Studname Address Stud-id Course Date_completed

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 30 -
101 ABC 12/20, DELHI 101 C 12/5/2005
102 XYZ 23/110, MUMBAI 101 C++ 17/9/2005
102 MSOFFICE 20/5/2005
102 VB 28/10/2005

The relation stud_course contains only the details of the students who have completed
one or more courses. Hence there is no wastage of memory. If we remove the student details
the course details will not be removed. Similarly if we modify the student details then the
number of modifications is very less. Thus all the inconsistencies are removed by applying
second normal form.

Third Normal Form (3NF):


A relation is said to be in third normal form, if it contains the following properties.
1. It must be in second normal form
2. It must not contain transitive dependencies

Transitive Dependency: The transitive dependency in a relation is a functional dependency


between two or more non-key attributes.
For example, let A, B, C are 3 attributes in a relation. Then if the functional dependencies
A  B and B  C exist then automatically AC exists. Such type of functional
dependencies is called transitive functional dependency.

Example: consider the following relation


EMPLOYEE (empno, empname, deptname, deptlocation)

Empno Empname Deptname Deptlocation

The functional dependencies are


Empno  deptname(A  B)
Deptname  deptlocation (B  C)
∴ Empno  deptlocation (A  C)

As a result, we have to face the following anomalies


i. Insertion Anomaly: A new department’s data cannot be inserted until an employee
data has been inserted.
ii. Deletion Anomaly: If we delete the employee details then the department details are
also deleted.
iii. Updation Anomaly: If the department name is changed then the number of
modification are more.

Empno Empname Deptname Deptlocation


101 AAA SALES DELHI
102 BBB PURCHASE MUMBAI

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 31 -
103 CCC SALES DELHI
104 DDD MKTG CHENNAI

To remove transitive dependencies, the above relation can be divided into two relations as
given below:

EMPLOYEE (empno, empname, deptno)


DEPT (deptno, deptname, deptlocation)

Empno Empname Deptno Deptno Deptname Deptlocation


101 AAA 10 10 SALES DELHI
102 BBB 20 20 PURCHASE MUMBAI
103 CCC 10 30 MKTG CHENNAI
104 DDD 30

Boyce-Codd Normal Form (BCNF):


A relation is in BCNF if and only if every determinant is a candidate key. For example,
consider the following relation:

Stno Subject Lecturer Marks


100 Physics AAA 75
100 Chemistry BBB 65
101 Computers CCC 68
102 Physics AAA 79

Suppose for one subject there can be any number of lecturers, but one lecturer can teach only
one subject. Then the functional dependencies in the above relation are

Stno Subject Lecturer Marks

Here the primary key is a composite key containing stno and subject. The remaining two
attributes can be derived from it. A student may have more than one subject. For each subject,
a student will have only one lecturer. Hence the functional dependencies are as follows:
Stno, subject  lecturer, marks
Lecturer  subject
There are no transitive dependencies.
Anomalies:
1. If the lecturer of Physics has been changed from AAA to MMM, then the number of
modifications is more.
2. If we want to insert a row, it cannot be done until a student is there.
3. If a student details deleted then the lecturer details also lost.
Thus, for removing these anomalies we have to apply BCNF in the following way.
1. If the determinant is not a candidate key then make it a part of composite primary key.
2. Then apply 2NF and 3NF if necessary

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 32 -

By applying first point the above relation becomes as shown below:

Stno Lecturer Subject Marks

Now, the determinant Lecturer becomes a part of composite primary key. The attribute
Subject is a non-key attribute and functional dependency on Lecturer. The above relation in
1NF but not in 2NF as there is a partial dependency, Lecturer  Subject
It can be removed by breaking the table in the following way

Stno Lecturer Marks Lecturer Subject

The above two relations are also in 3NF. Hence it is also in BCNF.

Note: If the relation has only one candidate key then both BCNF and 3NF are equal.

Stno Lecturer Marks Lecturer Subject


100 AAA 75 AAA Physics
100 BBB 65 BBB Chemistry
101 CCC 68 CCC Maths
102 AAA 79

Fourth Normal Form (4NF):


A relation is in 4NF if it is in BCNF and contains no multi-valued dependencies.

Multi-valued Dependency: It is a type of dependency that exists when there are atleast three
attributes. Suppose, A, B and C are three attributes then for each A value there exists a set of
B and C values, and B and C are independent then they are called multi-valued dependencies.
For example, consider the following relation

Course Instructor Textbook


Accounts A1 T1
A2 T2
Computers C1 T3
C2 T4

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 33 -
Here, each course has a set of instructors and each course has a set of textbooks. The
textbooks for a given course are independent of Instructor. If we convert the above relation
into 1NF then

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .


- 34 -

Course Instructor Textbook


Accounts A1 T1
Accounts A1 T2
Accounts A2 T1
Accounts A2 T2
Computers C1 T3
Computers C1 T4
Computers C2 T3
Computers C2 T4

The primary key of this relation is (course, instructor, textbook). The above relation contains
redundant data and there is no determinant. Hence it is in BCNF and the relation has many
drawbacks. In this case, the above relation can be divided into two separate relations in the
following way:

INSTRUCTOR BOOK
Instructor Course Textbook Course
A1 Accounts T1 Accounts
A2 Accounts T2 Accounts
C1 Computers T3 Computers
C2 Computers T4 Computers

Thus by applying 4NF, the above two relations are free from anomalies.

Fifth Normal Form (5NF):


It is also called Projection Join Normal Form (PJNF). This normal form is based on
join dependencies.

Join Dependency: Let R be a relation. R1, R2, R3,…,Rn be a decomposition of R. If all these
decompositions are combined then the original relation R is formed. This is called Loss less
join decomposition, i.e. if R = R1 U R2 U R3 …… U Rn, then we say that R satisfies Join
dependency.
Eg:
Domain Key Normal Form (DKNF):
A relation is said to be in DKNF, if all possible types of dependencies that should hold
on the relation can be enforced simply by implementing the domain constraints and key
constraints on the relation. It is the ultimate normal form that takes into account all the
possible types of dependencies and constraints.
Eg:
DENORMALIZATION

Denormalization is the opposite of Normalization. It is the process of increasing


redundancy in the database either for convenience or to improve performance.
For major applications or even simple application where tasks do not readily plan to
fully normalized tables, once the analysis complete, the design process may need to
SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .
- 35 -
denormalize some of the tables in order to build an application that is responsive and plans to
the user’s tasks.
Denormalization of frequently performed operations or calculations can be used to
improve performance. For example, the data contained in the monthly transaction table is
completely redundant; because everything can be derived from the daily transaction table
using SQL statements. But the monthly summary information is very frequently used and
calculating it each and every time will slow down the application resulting in poor response
times.

SRI KRISHNA CHAITANYA DEGREE & PG COLLEGE , NELLORE .