Ch-04 (DB) - Entity - Relationship Model
Ch-04 (DB) - Entity - Relationship Model
Chapter 4
Entity- Relationship
Model
Contents
• Entity- Relationship Model
• Elements of E-R Model
• Existence Dependency
• Modeling Multi-valued Attributes
• Modeling Repeating Groups
• Modeling Time-dependent Data
• Supertypes & Subtypes
• Aggregation
• Specialization & Generalization
• Union Type or Category
• Projects - E-R Model
Entity- Relationship Model
Chapter 4 - Entity- Relationship Model
Entity- Relationship Model
• Entity-Relationship model (or E-R model) popular and widely used conceptual
data model
• Logical representation of the data for an organization or a business area
• Data/information shown through ER-model is ultimately implemented as a
database
• E-R model describes the data structure of the database that is implemented as a database
• 1976 E-R model was introduced by Peter Chen
• Expressed in terms of
• entities (i.e. objects) in a system
• relationships between entities
• attributes (or properties) of both the entities and their relationships
• Allows logical designer to specify constraints on the entities or relationships
between entities
• E-R model is expressed graphically with the help diagram
Advantages E-R Model
+ Simplicity
• Because if we know the relationships between entities and attributes, then we can easily
draw an ER diagram
+ Visual Representation
• Describes the data structure of the database graphically with the help of the E-R diagram
• Helps a database designer to create a successful database very easily and efficiently
+ Effective Communication Tool
• For a database designer to get different views of data of an organization
+ Integrated with Relational Data Model
• Integrated with a relational data model
• Can easily be converted to the relational data model by simply converting the E-R model
into tables
+ Easy Conversion to any Data Model
• Can easily be converted to another data model like a hierarchical data model, or network
data model
E-R Diagram
• Graphical representation of an
E-R model
• Shows different entities and their
relationships to each other
within a system
• Different standard symbols are
used to represent entities and
relationships between them
• Basically, E-R diagrams are the
designing tools and
documentation for a system
Elements of E-R Model
Chapter 4 - Entity- Relationship Model
Entities
• Entity Anything in a real-world system that is important in the system and
has a set of different attributes or properties
• An entity can be
• an object with a physical existence a people, a place, etc.
• a concept or idea a university course, account, a job, an event that is relevant to a
given system
• For example: a college system may include entities like students, teachers,
courses, and subjects, etc.
• Person Teacher , Student, Player, Doctor, Employee, Customer
• Place City, Country, Province or State, Store, Warehouse
• Object Furniture, Vehicle, Equipment, Building
• Concept Account, Programming, Invoice, Marks, Course
Entity Type
• A collection (or set) of entities that have the same attributes (properties or characteristics)
• Entity type or Entity class
• For example:
• Entity a particular employee of an organization
• Entity Type a set of all employees of an organization
• Similarly, STUDENT and TEACHER represent two different entity types in a college or
university
• STUDENT entity type a set of all students
• TEACHER entity type a set of all teachers
• In E-R model capital letters are used for name of entity type
• A rectangle symbol is used to represent an entity type
• Name of the entity type is written inside this symbol
• All entities in a specific entity type share the same attributes
• but each entity has its own value(s) for each attribute
Entity Set
• A set of all entities in a particular entity type in the database at a given point
of time
• For example
• Entity set EMPLOYEE consist of all employees in an organization
• Entity set STUDENT consist of all students in the university/college
• Same name is usually used for both entity type and entity set
• STUDENT refers to both entity type as well as a set of all students in the database
Entity Instance
• A member of an entity type
• Representation of a particular entity
• such as a student of roll number 104
• Described by the values of attributes of the entity
• Entity type described just once in a database
• one STUDENT entity type in most universities or colleges
• Many instances of that entity type represented by data stored in database
• May be hundreds or thousands of instances of STUDENT entity type stored in database
• Each entity instance of an entity type has its own values
Attributes
• Characteristics or properties of an entity that describe it
• All attributes have values
• For example a particular student of a class can be described by his/her roll
number, name, father name, obtained marks, address, mobile number, etc.
• Attributes of a student entity
• Attributes are named
• If an attribute consists of a single word then use first letter as a capital letter and
other letters as lowercase letters
• If an attribute consists of two or more words then start each word with a capital letter
and other letters of the word as lowercase letters
• All instances of a particular entity type have the same attributes
• STUDENT entity type may have attributes Roll_No, Name, Father_Name, Marks,
Address, and Phone_No, etc.
• In E-R diagrams represented by ellipse (or oval shape)
Attribute Domain
• Values are assigned to the attributes of an entity
• Attribute values that describe each instance of an entity type become a major part of the data
stored in a database
• There exists a domain or range of values that can be assigned to attributes
• For example a student's name cannot be a numeric value. It has to be alphabetic
• A student's age cannot be negative, etc.
• Attribute domain A possible set of values that can be assigned to an attribute of entity
• A value set of an attribute
• Attribute domain may consist of a range of values or some specific values
• "Marks“, maximum value = 100 assign values from 0 to 100
• Domain for attribute "Gender“ either be "Male" or "Female“
• Different attributes can have the same domain
• Domain of an attribute "Name" is difficult to define
• because it consists of all alphabetic names of students
• An association of a domain with its attribute ensures the integrity (or accuracy) of a database
• ensures correct data entry
• Can specify the domain for an attribute at the DBMS level or application level
Required Attribute & Optional
Attribute
• Each attribute of an entity (or instance of an entity type) has a possible value
associated with it
• Required attribute attribute that must have a value for every entity instance
of an entity type
• Optional attribute attribute that may not have a value for every entity
instance of an entity type
• Required Attributes Roll-No, Name, and Address
• Optional Attributes Cell_No
• because some students may not have a mobile number or cell number
Types of Attributes
Simple Attribute
• An attribute that cannot be divided into smaller components
• Atomic attribute
• STUDENT entity type "Marks" and "Roll_No"
Composite Attribute
• An attribute that can be divided into smaller components
• Each component also represents a simple attribute with independent
meanings
• STUDENT entity type
• “Name” First-Name, Middle-Name, Last-Name
• Address attribute ZipCode, City, StreetAddress
Types of Attributes
Single-Valued Attribute
• An attribute that can have only one (or single) value for each entity instance
• Example1 Age of a student
• a particular student cannot have two values for the "Age" attribute
• Example2 "Roll_Number"
Multi-Valued Attribute
• An attribute that can have two or more values for each entity instance
• Examples a student can have more than one phone number or address
• Double-line ellipse is used to represent a multi-valued attribute
Types of Attributes
Stored Attribute
• An attribute that is stored in a database
• Base attribute
• Most of the attributes are stored attributes because their values are stored and accessed from the
database
Derived Attribute
• An attribute that does not exist in the physical database but its value is calculated (or derived) from
the values of other related attributes stored in a database
• For example "Age" and "Date-of-Birth" of a student
• If date-of-birth is stored in database age can be found out
• No need to store age of the student in the database if date-of-birth is stored
• Stored Attribute "Date-of-Birth“
• Derived Attribute "Age“
• Similarly
• Stored Attribute attributes in which marks of different subjects are stored
• Derived Attribute Total and average marks
Identifier
• Identifier An attribute (or a set of attributes) whose value uniquely identifies
an entity instance among other instances of the entity type
• Two or more instances of the entity type cannot have the same value for the
identifier attribute
• For example STUDENT entity type
• Each student is identified by his/her "Roll-No" or "Student ID“
• Identifier "Roll-No" or "Student ID"
• "Student Name" cannot be used as an identifier because many students may have the
same name
• In relational model primary key is used to identify the records uniquely
• In E-R diagram an entity identifier is underlined
Identifier
Simple Identifier
• An identifier that consists of only one attribute
• For example single attribute "Roll-No" of the STUDENT entity type as an identifier
Composite Identifier
• For some entity types, there is no single attribute that can serve as the identifier
• Two or more attributes used in combination may serve as the identifier
• Composite identifier An identifier that consists of two or more attributes
• For example a student can be identified by using both its "Roll-No" and "ClassID“
• An identifier that consists of a composite attribute composite identifier
• A composite attribute can be divided into smaller components i.e. two or more
attributes
Relationships
• Relationship an association among instances (or entities) of one or more entity types
• Indicates how the instances or entities of entity type(s) are related to each other
• Entity types that participate in a relationship Participants
• A relationship is established on the basis of interaction among these entities
• For example relationship exists between teacher and students because teacher teaches
students
• Each relationship is given a name
• An action word (such as teach, manage, and order) is used to name a relationship
• For example relationship between entity types MANAGER and DEPARTMENT: Manages
• In E-R diagram a relationship is indicated by a diamond symbol
• The diamond symbol is placed between the entity types' symbols connecting with lines
• The entities can be associated /connected to one another in different ways
• A BOOK-STORE orders BOOK
• A BOOK-STORE displays BOOK
• A BOOK-STORE stocks BOOK
• A BOOK-STORE sells BOOK
Degree of Relationships
• A relationship may consist of many entity types
• Degree of Relationship number of entity types that participate in a
relationship
• Degree of relationship "writes“ = 2
• because only two entity types are participating in this relationship, i.e. AUTHOR and
BOOK
• Binary relationship
• Unary relationship
• Ternary relationship
Binary Relationship
• Relationship between instances of two entity types
• Two entity types participate in this type of relationship
• Binary relationship has degree two
• Most common type of relationship used in data modeling (i.e. E-R diagrams)
• Types of binary relationship
• One-to-one relationship
• One-to-many relationship
• Many-to-many relationship
Binary Relationship
One-to-One (1:1) Relationship
• Used when a single instance of the first entity type is related to a single
instance of the second entity type
• For each instance of the first entity type, there is only one matching instance
in the second entity type
• On the other hand, for each instance in the second entity type, there is only
one matching instance in the first entity type
"A Supplier can supply many Parts in a "Many teachers may teach many classes
particular Project" with many students"
Cardinality Constraints
• Cardinality constraint A rule that specifies the number of instances of one entity type
that can (or must) be associated with each instance of another entity type
• The relationship types usually have certain constraints that limit the number of
instances of one entity type that can be associated with each instance of another
related entity type
• Relationship type A meaningful association among entity types
• Entity types: A and B cardinality
• one-to-one relationship between A and B
• Each instance in A can be associated with exactly one instance in B
• On the other hand, each instance in B must be associated with exactly one instance in A
• one-to-many relationship between A and B
• Each instance in A can be associated with many instances in B
• On the other hand, each instance in B must be associated with exactly one instance in A
• many-to-many relationship between A and B
• Each instance in A can be associated with many instances in B
• On the other hand, each instance in B can also be associated with many instances in A
Cardinality
• Cardinality Number of instances of one entity type that can be associated
with each instance of another entity type
• There are two categories of cardinality
• Maximum cardinality
• Minimum cardinality
Maximum Cardinality
• Maximum number of instances of one entity type that may be associated with
each instance of another related entity type
• Either "one" or "many“
• "one" denoted by small vertical line () on relationship line, next to the first entity type
or before the second entity type
• "many" denoted by crow’s foot ( > ) symbol
• Value of "Price" attribute depends upon date and time "Time stamp“
• May be associated with system date and time
• System date and time may be recorded into the database with each transaction
Supertypes & Subtypes
Chapter 4 - Entity- Relationship Model
Supertypes & Subtypes
• Entity type a collection of entities that have the same attributes (properties or
characteristics)
• In some situations, an entity type can be divided into several subgroups or subtypes
• Supertype entity type that can be divided into subtypes
• A supertype is a generic entity type that has a relationship with one or more subtypes
• Subtype a subset of a supertype and shares common attributes
• Behave like other entity types
• The identifiers (primary keys) of supertype and subtypes are always identical
• All properties of EMPLOYEE entity type apply
automatically to the TEACHER subtype but the
reverse is not true
• Each subtype has only one supertype
• Root entity type at the top of a hierarchy
IS-A Relationship
• Relationship between each subtype and its supertype IS-A or IS-AN relationship
• For example: "Shahbaz IS-A Student“, "Teacher IS-AN Employee“
• In ER diagram A rectangle with rounded edges
• The relationship is read from subtype to supertype
• The identifier (or primary key) of supertype is included with each subtype
• For example: two types of teachers in a university permanent teachers, visiting teachers
• Permanent teachers: Teacher-ID, Name, Address, Mobile-No, Basic Salary, and Allowances
• Visiting teachers: Teacher-ID, Name, Address, Mobile-No, Hours, and Rate Per Hour
• Each type has one or more attributes that are different from the other type
• Each subtype contains only those attributes that are not common
• Cardinality from subtype to supertype mandatory
• because an instance of a subtype is always an instance of the supertype
• Cardinality from supertype to subtype optional zero or one
• Exclusive relationship subtype and supertype are mutually exclusive, and each instance
of the supertype is required to be a member of exactly one subtype
• Each teacher must be a permanent teacher or visiting teacher
Inheritance Associated with Supertype/Subtype
• Inheritance is another important concept associated with subtypes and
supertypes
• Property by which all attributes (and relationships) of a supertype become
attributes of its subtypes
• This important property makes it unnecessary to include the attributes and
relationships of supertype with the subtypes
• These attributes need not be attached to the subtypes
Aggregation
Chapter 4 - Entity- Relationship Model
Aggregation
• Aggregation an abstraction concept, which is used to build a higher-level
object from its components
• For example, a computer is built by using various related components
• The aggregation abstraction allows designer to
• either decompose objects by breaking them into more detailed components
• or to aggregate objects, grouping them together into higher-level objects
• The hardware and software are further decomposed into their subparts
Specialization &
Generalization
Chapter 4 - Entity- Relationship Model
Specialization
• The process of identifying one or more subtypes and forming
supertype/subtypes relationships
• Specialization is the process of defining a set of subtypes or subclasses of the
supertype
• The subtypes are defined based on their characteristics
• Top-down process in which a higher-level entity type (supertype) is divided
into two more lower-level entity types (subtypes)
• Inheritance subclasses inherit all the attributes and relationships of their
superclass
Generalization
• The process of identifying a general entity type from a set of specialized entity
types
• Generalization is the reverse process of specialization
• Bottom-up process in which two or more entities can be generalized to a
higher level entity if they have some attributes in common
• Common features of subclasses are identified and generalized into a single
super-class
Inclusion of Constraints on
Generalization and Specialization
• Subclasses are disjoint if an entity can be a member of only one subclass
• Subclasses are non-disjoint if an entity can be a member of more than one
subclasses (i.e. subclasses are overlapping)
Step 4
• Each department has a chairman, while a chairman chairs only one
department.
Project 1
Step 5
• In a university, a teacher belongs to one and only one department. However,
a department may have at least one or many teachers. The teacher can be
visiting, part-time, or full-time.
Project 1
COMPLETE E-R MODEL OF UNIVERSITY SYSTEM
Project 2
• Consider a University’s teaching environment where the following are the
main requirements:
• A student takes different courses.
• On one seat, only one student is enrolled.
• A course is listed only if there is some student(s) enrolled in it.
• There is only one instructor to teach a particular course; however, an Instructor can
teach different courses.
• To teach a particular course, multiple classes of the course may be arranged.
• In a particular class, only one course is taught.
• Construct an ER diagram for this environment of the university.
Project 3
• Draw an E-R model according to the following requirements and take your own
assumptions (if needed):
• In an educational institute, there are several departments and a particular student belongs to one
of them. Each department has a unique department number, a name, a location, a phone number,
and is headed by a professor.
• Professors have a unique employee ID, name, phone number. We like to keep track of the
following details regarding student name, unique roll number, sex, phone number, DOB, age, and
one or more email addresses.
• Students have local addresses consisting of the hostel name and the room number. They also have
home addresses consisting of house number, street, city, and PIN (Postal Index Number). It is
assumed that all students reside in the hostels.
• A course taught in a semester of the year is called a section. There can be several sections of the
same course in a semester; these are identified by the section number. Each section is taught by a
different professor and has its own timings and room to meet.
• Students enroll for several sections in a semester. Each course has a name, number of credits, and
the department that offers it. A course may have other courses as pre-requisites. Professors also
undertake research projects. These are sponsored by funding agencies and have a specific start
date, end date, and amount of money given. More than one professor can be enrolled in a project
also a professor may be simultaneously working on several projects. A project has a unique project
Project 4
• Design an ER diagram to model the following scenario:
• For each person, we need to record his CNIC number, name, and address.
• Authors write books.
• Editors ensure that books are written in a manner that is suitable for publication.
• Every editor works for just one publisher.
• Editors and authors have quite different skills; someone who is an editor cannot be an author
and vice versa.
• A book may have several authors, just one author, or no authors (published anonymously).
• Every book has one editor assigned to it, who has a liaison (link or connection) with the
author(s) in getting the book ready for publication.
• Each book has a title, and an edition number (e.g. 1st, 2nd, 3rd).
• Each published book is assigned a unique 13-digit number (its ISBN); different editions of the
same book will have different ISBNs.
• Publishers are companies that publish (market/distribute) books.
• Each publisher is required to have a unique registration number (Reg#).
• A publisher also has a name and address that need to be recorded.
• A particular edition of a book is published by exactly one publisher. (Solution is given in
Project 5
• Draw an E-R diagram for the following given CASE STUDY:
• A company has several departments. Each department has a supervisor and at least
one employee. Employees must be assigned to at least one, but possibly more
departments. At least one employee is assigned to a project, but an employee may be
on vacation and not assigned to any projects. The important data fields are the names
of the departments, projects, supervisors, and employees, as well as the supervisor
and employee number and a unique project number.
Project 6
• Draw an E-R Model for "Aqsa & Co" that is a Chartered Accountants Firm.
Use the following assumptions about the Human resources department.
• There are many departments of the company having attributes Department Number,
Phone Number, and Address.
• Each person in the organization is considered to be an employee including the owner.
An employee may or may not belong to a department.
• There are many employees in the organization with attributes of Employee ID, Name,
Phone Number, Address, Hire-Date, Age, and Sex.
• An employee can go on leaves and leave has two types: Casual leave and Paid leave
and leaves have attributes Leave Date, Leave Type, and Number of days.
• The record of children of employees is also to be recorded. The attributes for the
children are Children number, Sex, and Age.
• The employees supervise projects running in the organization and each project has
attributes Project ID, Project Name, Start Date, and Completion Date.
• The company has some Laboratories in it and every project is completed in some
Laboratory. (Solution is given in book)
Project 7
• Draw an E-R diagram for the following given CASE STUDY:
• Every employee has a unique number assigned by the firm, a name, and date of birth.
Each employee has a job title. Each employee does only one type of job at a time, and
we only need to retain information about an employee’s current job.
• There are 11 different departments in the firm, each with a unique name. An
employee can report to only one department. Each department has a phone number.
To procure (obtain) various types of equipment, each department deals with many
suppliers. A supplier typically supplies equipment to many departments. We need to
store the name and address of each supplier and the date of the last meeting between
a department and a supplier. Many employees can work on a project. An employee
can work on many projects, but can only be assigned to at most one project. Project
information that is stored in the database are project No, project name, project cost,
and duration.
(Solution is given in book)
Project 8
• Consider a company which prepares Products by importing different Items
from different Suppliers in foreign countries, through shipment. The prepared
products are sold to different local Customers through their purchase Orders.
• Point out the main entities and construct an ER diagram for this company’s
database.
Project 9
• Draw an E-R diagram for the following given CASE STUDY:
• A large bank operates several divisions. Information Technology (IT) is operated as one
of these divisions. Within the IT division are many departments that are managed by
one manager, and all IT employees belong to one of these departments. The IT
division assigns it’s employees to one or more ongoing projects in the bank. A project
may be planned/ but not have any employees assigned to it for several months. Each
project will have a single employee assigned who acts as a project leader.
(Solution is given in book)
Project 10
• Draw an E-R diagram for the following given CASE STUDY:
• Emerging Electric wishes to create a database with the following entities and
attributes:
• CUSTOMER with the attributes Customer ID, Name, Address (Street, City, State, Zip Code), and
Phone-No
• LOCATION with the attributes Location ID, Name, Address (Street, City, State, Zip Code), and Type
(values of Business or Residential)
• RATE with the attributes Rate-Class and Rate-Per-KWH (KWH stands Kilo Watt Hour)
• After interviews with the owners, you have come up with the following business rules:
• A customer can have one or more locations.
• Each location can have one or more rates, depending on the time of day.
(Solution is given in book)
Project 11
• Draw an E-R diagram according to the following CASE STUDY. You can make your
own assumptions if needed. After identifying Entity types, some attributes are
given, others can be added according to your assumptions.
CASE STUDY
• A company "Ashan Corporation" deals in selling products to its customers after purchasing
products from different vendors. Vendors have attributes like VendorID, VenderName,
Address, and Phone.
• The company sends a purchase order to a vendor and provides a list of items to be purchased
by the company.
• An item (product) may be purchased from different vendors.
• Items are stored in the stock after they are received from the vendor.
• Customers send sale orders with a list of products to buy from the Ashan Corporation
company.
• Products are sent to customers with the invoice after receiving sale orders from customers.
Invoice has attributes Invoice-No, Date, etc.
• Customers make the payments according to the invoice after receiving the invoice and make
payments on some date.
Project 12
• Draw an E-R diagram according to the following requirements:
• A company has different employees. The attributes of EMPLOYEE include Emp_ID,
Emp_Name, Emp_Address, and Emp_DOB. The employees work on different projects.
The attributes of PROJECT are Project_ID, Project_Name, and Project_Start_Date.
Each employee may be assigned to one or more projects or may not be assigned to
any project. A project must have at least one employee assigned or may have any
number of employees assigned to it. An employee’s billing rate may vary by one
project to another. The company wishes to record the project billing rate for each
employee when assigned to a particular project.
PM Series
Database Management
by
CM Aslam, Aqsa Aslam, Mudassir
Ahmad & Hafiz Saeed Ahmad