DBMS Er
DBMS Er
ER Modeling
Database Design Techniques
Top down Approach
Top down starts by defining the data sets and then define the
data elements within those sets. As a result of this method,
you generally end up with redundant information in one or more
tables.
Bottom Up approach
Bottom up starts by defining the required attributes and then
grouping them to form the entities. Another term used for this
method is normalization from functional dependencies.
2
ER Modeling
Top down Approach
3
ER modeling
• ER modeling: A graphical technique for understanding
and organizing the data independent of the actual
database implementation.
• Entity: Any thing that may have an independent
existence and about which we intend to collect data.
Also known as Entity type. E.g.: Trainee
• Relationships: Associations between entities. E.g.:
Trainee belongs to a Batch
• Attributes: Properties/characteristics that describe
entities.eg: Trainee Name, BatchName, DOB, Address,
etc.
4
Association
between the
instances of one or
more entity types
8
Attributes
• The set of possible values for an attribute is called the domain
of the attribute
Example:
• The domain of attribute marital status is having four values: single,
married, divorced or widowed.
10
Degree of a Relationship
• Degree: the number of entity types involved
• One Unary
• Two Binary
• Three Ternary
11
Cardinality Ratios
• In ER model, a relationship is an association among entities
(records) of one or more entity sets. Cardinality ratio or
mapping cardinalities is a concept that describes binary
relationship set (a relationship that connects two entity
sets) and its types.
• It is about the maximum number of entities of one entity
set that are associated with the maximum number of
entities of the other entity set.
E.g.:
Employee head-of department (1:1)
Lecturer offers course (1:N) assuming a course is taught by
a single lecturer
Student enrolls course (M:N)
The minimum and maximum values of this connectivity is called the cardinality of the
relationship
13
compiled by Dr Vijay Singh CSE, Graphic Era
14
Deemed to be University, Dehradun
compiled by Dr Vijay Singh CSE, Graphic Era
15
Deemed to be University, Dehradun
Participation constraints in DBMS
This constraint specifies the number of
instances of an entity that are participating
in the relationship type.
29
ER Modeling -Notations
A derived attribute is based on another attribute. For
Attribute
example, an employee's monthly salary is based on the
employee's basic salary and House rent allowance.
30
ER Modeling -Notations
Customer Cardinality specifies how many instances of an Entity
relate to one instance of another Entity. M,N both
1
represent ‘MANY’ and 1 represents ‘ONE’
Cardinality
1 M
Account Transaction
Employee
31
Composite attribute
floor building
DOB
Name Address
E# Designation
Employee
Manages
Employee
33
Role names
Manages
Employee
Manager
34
Binary Relationship
35
Ternary Relationship
Medicine
36
Relationship participation
1 head 1
Employee department
of
partia
l otal
T
Employees 1 1 Departments
Manages
M
Works_In 1
since
Attributes of a Relationship
Medicine
Number of days
dosage
E# Id name
----
1 has N dependant
Employee
40
Case Study – ER Model For a college
DB
Assumptions :
• Find relationships
• Draw complete E-R diagram with all attributes including Primary Key
• DEPARTMENT
• STUDENT
• COURSE
• INSTRUCTOR
43
Steps in ER Modeling
44
Steps in ER Modeling
Step 3: Identify the key attributes
• Deptname is the key attribute for the Entity “Department”, as it identifies the
Department uniquely.
• Course# (CourseId) is the key attribute for “Course” Entity.
• Student# (Student Number) is the key attribute for “Student” Entity.
• Instructor Name is the key attribute for “Instructor” Entity.
45
Entities
DEPARTMENT LOCATION
NAME
DEPARTMENT
STUDENT
STUDENT DATE OF
STUDENT#
NAME BIRTH
COURSE
PRE COURSE
COURSE# DURATION
REQUISITE NAME
INSTRUCTOR
INSTRUCTOR
TELEPHONE# ROOM#
NAME
48
49
50
Specialization
• A lower-level entity set inherits all the attributes
and relationship participation of the higher-level
entity set to which it is linked.
• A lower-level entity set may have additional
attributes and participate in additional relationships
Specification
• Disjoint/Overlapping
• Completeness constraint
(use double lines)
• total : an entity must
belong to one of the
lower-level entity sets
• partial: an entity need
not belong to one of the
lower-level entity sets
Category owner is the subclass of the set union of entity types person, company and bank
Aggregation
Consider the ternary relationship works-on, which we saw earlier
Suppose we want to record managers for tasks performed by an
employee at a branch
E-R Diagram With Aggregation
Design Considerations
• Use of entity sets vs. attributes
• Whether we want to keep additional information
• Use of entity sets vs. relationship sets
• Actions among entities are usually represented by
relationships
• Binary versus n-ary relationship sets
• N-nary relationships are usually more natural for actions
among entity sets
• Weak entity set vs. strong entity set
• Generalization
Notations
Notations
COMPANY ER Schema Diagram
using (min, max) notation
Designing an ER Diagram
Consider the following set of requirements for a University database. Design an ER
diagram for this application:
• The university keeps track of each student's name, student number, social security
number, current address and phone number, permanent address and phone number,
birthdate, sex, class (freshman, graduate), major department, minor department (if
any), degree program (B.A., B.S., ... Ph.D.). Some user applications need to refer to
the city, state, and zip code of the student's permanent address and to the student's
last name. Both social security number and student number are unique for each
student. All students will have at least a major department.
• Each department is described by a name, department code, office number, office
phone, and college. Both the name and code have unique values for each department.
• Each course has a course name, description, course number, number of credits, level
and offering department. The course number is unique for each course.
• Each section has an instructor, semester, year, course, and section number. The
section number distinguishes sections of the same course that are taught during the
same semester/year; its value is an integer (1, 2, 3, ... up to the number of sections
taught during each semester).
• A grade report must be generated for each student that lists the section, letter
grade, and numeric grade (0,1,2,3, or 4) for each student and calculates his or her
average GPA.
University ER Diagram
Degree DName DCode OfficeNumber
Name StudentID SSN
Major In
Birth date
OfficePhone
Department
Sex Student
College
Class Minor In
Address
CName
Grade_Report
CourseDesc
Letter Grade Instructor Year Course
CNumber
GPA
Credits
Numeric Grade Section Belong_To
SectionNumber Semester
ER DIAGRAM FOR A BANK
DATABASE
An ER diagram for an AIRLINE database schema.
Enhanced ER Model
Superclass/Subclass
• Subclasses
• Subgroupings of the entities of an entity type
• An entity type as a superclass of subclasses
• Examples
• EMPLOYEE {SALARIED_EMPLOYEE,
HOURLY_EMPLOYEE}
• PATIENT {OUTPATIENT, INPATIENT}
• STUDENT {FULL-TIME, PART-TIME}
Superclass/Subclass
• “IS-A” relationship
• Members of a subclass must be members of the
superclass
• A FULL-TIME STUDENT ISA STUDENT
• Not every entity in a superclass be a member of
a subclass
• Subclasses
• Should have meaningful subgroupings
• Should be related to database applications
Entity Type Inheritance
• Type Inheritance among Classes
• Inherited Attributes
• a subclass inherits the attributes of the
superclass
• HOURLY_EMPLOYEE (Name, SSN, Address)
• Local (Specific) Attributes
• a subclass may have its own attributes
• HOURLY_EMPLOYEE (Hourly_rate)
• SALARIED_EMPLOYEE (Annual_salary)
EER Example