DATABASE
MANAGEMENT SYSTEMS
Module III
Database Design
E-R Model
E-R (Entity-Relationship) Model
Most popular conceptual model used for
designing a database.
The E-R model views the real world as a set of
basic objects (known as entities), their
characteristics (known as attributes) and
associations among these objects (known as
relationships)
The information gathered from the user forms
the basis for designing the E-R model
Entity and Attribute
An entity is a distinguishable object that has an
independent existence in the real world
The attributes are the properties of an entity
that characterize and describe it
For example, BOOK entity can have Price as
an attribute
Entity and Attribute
Entity Type: A set or a collection of entities that share
the same attributes but different values
E.g set of all publishers who publish books can be
defined as the type publisher.
Entity Set: The collection of all instances of a particular
entity type in the database at any point of time. Each
entity set is referred to by its name and attribute values.
Usually referred to using the same name as the entity
type
Entity and Attribute
Key Attribute: The attribute (or combination of
attributes) whose values are distinct for each
individual instance of an entity type. It is used to
uniquely identify each instance of an entity type.
An entity type may have more than one key
attribute.
Superkey:
A set of one or more attributes, when taken
together, helps in uniquely identifying each
entity is called a superkey .
example
attribute p-id of entity type publisher can be
used to uniquely identify each instance. It is a
superkey. P-name can also used as a superkey.
Similarly combination of p-id and p-name is also
a super key. The combination of all attributes is
also a super key.
Candidate Key, Primary Key , Composite key
Candidate Key: A minimal super key that does not
contain any extra attributes in it.
For eg p-id alone can uniquely identify each entity,
other attributes are not required. So it is a candidate
key. P-name is also a candidate key. But combination
of p-id and p-name is not a candidate key
Primary Key: The candidate key, which is chosen by
the database designer to uniquely identify entities.
Composite key : If a primary key is formed by the
combination of two or more attributes.
Weak and Strong Entity
Weak Entity : An entity type that does not have any key
attribute of its own is called a weak entity.
It has a partial identifying attribute which is known as partial
key(discriminator).
Strong Entity : An entity type that has a key attribute is called
a strong entity type
For eg, consider the entity type EDITION with attributes
edition_no and type. It depends upon another entity Book
for its existence, as an edition cannot exist without a book.
Thus edition is a weak enity and Book is a strong entity
Weak and Strong Entity
The entities belonging to a weak entity type are identified by
the attributes of a strong entity type in combination of one of
their attribute, thus the strong entity types are known as
identifying or parent entity type. The weak entity type, on
the other hand, is known as child or subordinate entity type
Attribute Types
Simple and composite
Single valued and multivalved
Stored and derived
NULL values
Attribute Types
1. Simple (atomic) and composite
Simple attribute cannot be divided into sub parts
E.g. Designation, Age, Gender etc
Composite attributes can be divided into sub parts
Composite attributes help to group together
related attributes
Name attribute can me divided into First name,
Middle name and Last name
Attribute Types
2. Single valued and multi valued
Single valued attributes have a single value for a
particular entity
E.g. Age
Multi valued attributes have a set of values for a
particular entity
E.g. College_Degree
Attribute Types
3. Stored and Derived attributes
Attributes that are stored in to the database is called
stored attributes
Attributes that are derived from the values of other
related attributes or entities are called derived attributes
E.g. The attribute Age can be derived from the stored
attribute Date_Of_Birth and the current date,No of
persons in the department
Attribute Types
4. Null attributes
A null value is used when an entity does not
have a value for an attribute
Relationships
Relationships: A relationship is an association between two or
more entities
E.g. The relationship PUBLISHED_BY associates a book with
its publisher
Relationship set: Set of relationships of the same type
A relationship type R among n entity types E1, E2 . . . En defines
a set of associations among entities from these entity types
The relationship between a weak entity and its identifying
entity type is known as identifying relationship.
E-R Diagram
An E-R diagram is a specialized graphical tool that
demonstrates the inter-relationships among various entities
of a database
It is used to represent the overall logical structure of the
database
E-R Diagram
E-R Diagram Naming Conventions:
The meaning of the context is conveyed as much as
possible
The usage of names should be consistent throughout the E-
R diagram
The usage of hyphens, spaces, digits and special characters
should be avoided
E-R Diagram
Singular names should be used for entity types
If a primary key of one entity type is used as a
foreign key in another entity type, it should be
used unchanged or with some extensions
E-R Diagram Notations
Entity Type
Relationship
Weak Entity Type Identifying
Relationship
E-R Diagram Notations
Multi valued
Attribute
Attribute
Partial key of weak
entity Attribute
Derived Attribute
Key Attribute
E-R Diagram Notations
Connects attribute to entity
type and entity types to
relationship types
Total participation
E-R Diagram Notations
1 1 M 1
1:1 Relationship M:1 Relationship
M N
1 M
1:M Relationship M:N Relationship
E-R Diagram Example
Component of ER Diagram
Entity:
An entity may be any object, class, person or
place. In the ER diagram, an entity can be
represented as rectangles.
Consider an organization as an example-
manager, product, employee, department etc. can
be taken as an entity.
Weak Entity
An entity that depends on another entity called a
weak entity. The weak entity doesn't contain any
key attribute of its own. The weak entity is
represented by a double rectangle.
Attribute
The attribute is used to describe the property of
an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name,
etc. can be attributes of a student.
Snam
Sid e
STUDENT
Addr
Age ess
Key Attribute
The key attribute is used to represent the main
characteristics of an entity. It represents a primary
key. The key attribute is represented by an ellipse
with the text underlined.
Snam
Sid e
STUDENT
Addr
Age ess
Composite Attribute
An attribute that composed of many other
attributes is known as a composite attribute. The
composite attribute is represented by an ellipse,
and those ellipses are connected with an ellipse.
Multivalued Attribute
An attribute can have more than one value. These
attributes are known as a multivalued attribute.
The double oval is used to represent multivalued
attribute.
For example, a student can have more than one
phone number.
Derived Attribute
An attribute that can be derived from other
attribute is known as a derived attribute. It can be
represented by a dashed ellipse
For example, A person's age changes over time
and can be derived from another attribute like
Date of birth. Snam
Sid e
STUDENT
Addr
Age ess
Relationship
A relationship is used to describe the relation
between entities. Diamond or rhombus is used to
represent the relationship.
Types of relationship are as follows:
a. One-to-One Relationship
When only one instance of an entity is associated
with the relationship, then it is known as one to
one relationship.
For example, A female can marry to one male,
and a male can marry to one female.
One-to-many
relationship
When only one instance of the entity on the left,
and more than one instance of an entity on the
right associates with the relationship then this is
known as a one-to-many relationship.
For example, Scientist can invent many
inventions, but the invention is done by the only
specific scientist
Many-to-one
relationship
When more than one instance of the entity on the
left, and only one instance of an entity on the
right associates with the relationship then it is
known as a many-to-one relationship.
For example, Student enrolls for only one course,
but a course can have many students.
Many-to-many
relationship
When more than one instance of the entity on the
left, and more than one instance of an entity on
the right associates with the relationship then it is
known as a many-to-many relationship.
For example, Employee can assign by many
projects and project can have many employees.
E-R Diagram:
E-R Diagram for Online Book Database
E-R Diagram example
Participation Constraints
Total Participation − Each entity is involved in
the relationship. Total participation is represented
by double lines.
Partial participation − Not all entities are
involved in the relationship. Partial participation is
represented by single lines.
Total & Partial Participation
Q) Draw E- R diagram for BANK MANAGEMENT
SYSTEM
o Entities and their Attributes are :
o Bank Entity : Bank Name, Bank Code and Address.
o Customer Entity : Customer_id, Name, Phone
Number and Address.
o Branch Entity : Branch_id, Name and Address.
o Account Entity : Account_number, Account_Type
and Balance.
o Relationships are :
o Bank has Branches => 1 : N
o Branch maintain Accounts => 1 : N
o Account held by Customers => M : N
E-R Diagram for Online Book Database
Enhanced E-R (EER)Model
Some aspects of a database such as inheritance
among various entity types cannot be expressed
using the basic E-R model
These aspects can be expressed by using the
enhanced E-R model or EER diagrams and the model
is called EER model
Extended E-R features include specialization and
generalization
Enhanced E-R Model
SPECIALIZATION
An entity type may include sub-groupings of its
entities in such a way that entities of one
subgroup are distinct in some way from the
entities of other subgroups
The process of refining the higher-level entity
types (super class) into lower-level entity types
(subclass) by adding some additional features to
each of them is a top-down design approach and
is known as specialization
Specialization
Enhanced E-R Model
For eg, the entity type Book can be classified further
into three types, namely textBook, Language_Book
and Novel. These entity types are described by the
set of attributes of Book and some additional set of
attributes (local attributes) that differentiate them
from each other.
The entity text Book may have additional attributes
subjects like maths, science, computer etc.
Language Book may have language such as French,
German , Japanese etc. and Novel may have the
attribute type(Fiction ,mystery, fantasy etc).
This process of defining the subgroups are called
specialization.
Enhanced E-R Model
Specialization process allows to do the following
Define a set of subclasses of an entity type
Establish additional specific attributes with each
subclass
Establish additional specific relationship types
between each subclass and other entity types or
other subclasses
Subclass and Super class
Subgrouping of an entity set is called subclass
Entity type from which the subclasses are
derived is called super class
Specialization is the process of defining a set of
subclasses of an entity type
Enhanced E-R Model
specialization
Enhanced E-R Model
Generalization: The design process may also
follow a bottom-up approach in which multiple
lower-level entity types are combined on the
basis of common features to form higher-level
entity types. This process is known as
generalization
Generalization
Generalization
Enhanced E-R Model
Aggregation
o In aggregation, the relation between two
entities is treated as a single entity.
o In aggregation, relationship with its
corresponding entities is aggregated into
a higher level entity.
For example: Center entity offers the Course entity
act as a single entity in the relationship which is in a
relationship with another entity visitor. In the real
world, if a visitor visits a coaching center then he will
never enquiry about the Course only or just about the
Center instead he will ask the enquiry about both.
ER Model to Relational Model
Rule-01: For Strong Entity Set With
Only Simple Attributes-
• A strong entity set with only simple
attributes will require only one table in
relational model.
• Attributes of the table will be the
attributes of the entity set.
• The primary key of the table will be the
key attribute of the entity set.
Example
Rule-02: ForStrong Entity SetWith CompositeAttributes-
• A strong entity set with any number of
composite attributes will require only one table
in relational model.
• While conversion, simple attributes of the
composite attributes are taken into account and
not the composite attribute itself.
Rule-03: For Strong Entity Set With Multi Valued
Attributes-
A strong entity set with any number of multi valued
attributes will require two tables in relational model.
One table will contain all the simple attributes with
the primary key.
Other table will contain the primary key and all the
multi valued attributes.
Schema : Student(Roll_no, City)
Schema : Student(Roll_no, Mobile_no)
Rule-04: Translating Relationship Set into a Table-
A relationship set will require one table in
the relational model.
Attributes of the table are-
Primary key attributes of the
participating entity sets
Its own descriptive attributes if any.
Set of non-descriptive attributes will be
the primary key.
Rule-05: For Binary Relationships With Cardinality
Ratios-
Case-01: Binary relationship with
cardinality ratio m:n
Case-02: Binary relationship with
cardinality ratio 1:n
Case-03: Binary relationship with
cardinality ratio m:1
Case-04: Binary relationship with
cardinality ratio 1:1
Case-01: For Binary Relationship With Cardinality Ratio m:n
Here, three tables will be required-
A ( a1 , a2 )
R ( a1 , b1 )
B ( b1 , b2 )
Case-02: For Binary Relationship With Cardinality Ratio 1:n
Here, two tables will be required-
A ( a1 , a2 )
BR ( a1 , b1 , b2 )
Here, combined table will be drawn for the entity set B
and relationship set R.
Case-03: For Binary Relationship With Cardinality Ratio m:1
Here, two tables will be required-
AR ( a1 , a2 , b1 )
B ( b1 , b2 )
NOTE- Here, combined table will be drawn for the entity set
A and relationship set R.
Case-04: ForBinary RelationshipWith Cardinality Ratio 1:1
Way-01:
AR ( a1 , a2 , b1 )
B ( b1 , b2 )
Way-02:
A ( a1 , a2 )
BR ( a1 , b1 , b2 )
ER Model to Relational Model
Applying the rules, minimum 3 tables will be required-
MR1 (M1 , M2 , M3 , P1)
P (P1 , P2)
NR2 (P1 , N1 , N2)
Applying the rules that we have learnt,
minimum 6 tables will be required-
Account (Ac_no , Balance , b_name)
Branch (b_name , b_city , Assets)
Loan (L_no , Amt , b_name)
Borrower (C_name , L_no)
Customer (C_name , C_street , C_city)
Depositor (C_name , Ac_no)
E-R Diagram for Online Book Database
A relational (database) schema
A relational (database) schema is a set of table
definitions (stored base tables or derived views),
constraints, and derivation rules.