0% found this document useful (0 votes)
34 views

6.Entity Relationship Diagram

Uploaded by

simunobo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

6.Entity Relationship Diagram

Uploaded by

simunobo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

DatabaseManagement

E-R Data Model


System
2

Design
Phases

User
Requiremen
ts
Specificatio Conceptual-
n design Phase
[ER Diagram] Logical-design
[Phase Relational
Schema]
Physical-
design Phase
[Relational
Database]
3

Conceptual Design >> E-R Data


Model
▸ Entity-relationship(E-R) data model is used to represent the conceptual design. It maps the meanings and
interactions of real-world enterprises onto a conceptual schema.
▸ The E-R data model perceives the real world as consisting of basic objects, called entities, and relationships
among these objects.
▸ The E-R model has an associated diagrammatic representation, the E-R diagram. E-R diagram can express
the overall
logical structure of a database graphically.
▸ Three principal concepts:
 Entity sets
 Attributes
 Relationship sets
▸ We will consider Chen Model Notations for our E-R Diagram.
4

E-R Diagram >>


Components
▸ Entity: It is a real-world object about which we collect data. In other words, it is a definable thing that can
have data stored about it.

▸ Entity Set: An entity set is a set of entities of the same type that share the same properties or attributes.

▸ Attributes: Attributes are descriptive properties of the entities in the entity set. Each entity has its own
value for each attribute.

▸ Relationship: It is an association among several entities.

▸ Relationship Set: It is a set of relationships of the same type.


5

E-R Diagram >>


Components
Attribute Relationship

Entity

Relation:
Borrower Entity Set

Relationship Set
6

E-R Diagram >>


Attributes
Simple – Attribute value is atomic and can’t be
divided into subparts. SimpleAttr

Composite – Attributes that can be divided into


subparts i.e. other attributes. address

city

zipCode

street

Derived – Attributes that can be calculated from


other related attributes. age

Multivalued – Attributes having more than one


values (a set of values) for a specific entity. ContactNo
7

E-R Diagram >> Relationship


Attributes

One-to-Many Relationship Many-to-Many Relationship


Set Set
7

E-R Diagram >> Relationship


Attributes

Diamonds represent relationship sets.


8

E-R Diagram >> Relationship


Attributes
A descriptive attribute is tied to a relationship and not to any individual entity.
Relationship: "Borrow" between Customer and Loan.
Descriptive Attribute: borrow_date (the date when the customer borrowed the
loan).
Relationship: "WorksOn" between Employee and Project.
Descriptive Attribute: hours_worked (indicating the number of hours an employee
worked on a specific project).
Cannot Belong to Entities:
These attributes cannot logically belong to either of the connected entities
individually. For example, borrow_date makes sense only in the context of the
relationship between Customer and Loan.
8

E-R Diagram >> Relationship


Attributes
9

E-R Diagram >>


Keys
Superkey – A set of one or more attributes that, taken
collectively, allow us to identify uniquely an entity in the entity
set.

Candidate key – A minimal (irreducible) superkey such that


no proper subset of its attributes is also a superkey.

Primary key – The candidate key chosen to be used for


identifying entities and accessing records.

Key attribute – An attribute that is part of a (primary) key.


KeyAttribute

Partial key/Discriminator – an attribute that when combined with


the key attribute of the owner entity, provides identification for
the weak entity.
PartialKeyAttr
1
0
Relational Database
Keys
Composite key – A key that is composed of
more than one attribute.

Foreign key – An attribute or combination


of attributes in one table whose values
must either match the primary key in
another table or be null.
Foreign keys are used to ensure referential
integrity, the condition in which every
foreign key entry must either be null or a
valid value in the primary key of the
related table.
1
1
E-R Diagram >> Entity
Sets
Strong Entity Set – A Strong Entity is a
type of entity that has a key Attribute. id name street city
Strong Entity does not depend on
other Entity in the Schema. It has a
primary key, that helps in identifying
it uniquely, and it is represented by a customer
rectangle.

Weak Entity Set – It is one whose existence is


dependent on another (identifying) entity set.
The primary key attributes of the identifying entity set,
along with the discriminator (partial key) attributes of
its own are used to uniquely identify each weak entity.
Here,
Partial key is payment-number . But it is not enough to
uniquely identify tuples. It depends on Foreign key loan-
number. A weak entity type is represented by a Double
Rectangle.
1
2
E-R Diagram >> Entity
Sets
Associative Entity Set – This type of entity
set is used in a many-to-many enroll
relationship. student course
When you need a relationship to be ment
involved in a relationship then the former
relationship is converted to an associative
entity.
enroll
student course
ment

teach

teacher
1
3
E-R Diagram >>
Example
1
4
E-R Diagram >> Relationship
Sets
Non-Identifying Relationship Set – A relationship where child
entity can exisits without parent entity, and primary key of
child doesn’t contain primary key component of parent entity.
RelSet

In terms of relationship strength, it is also known as weak


relationship.

Identifying Relationship Set – A relationship where child


entity is existence-dependent on parent (identifying) entity,
and primary key of child entity contains primary key Identifying
RelSet
component
The of parent
identifying entity. set should not have any
relationship
descriptive attributes, since any such attributes can instead
be associated with the weak entity set.

In terms of relationship strength, it is also known as strong


relationship.
1
4
E-R Diagram >> Relationship
Sets
Non-Identifying Relationship Example
Entities:
1.Branch:
•Attributes: branch_id (Primary Key), branch_name.
2.Book:
•Attributes: book_id (Primary Key), title, branch_id (Foreign Key).
Relationship:
Each book is associated with a library branch, but books can exist independently of
a branch (e.g., relocated to another branch).
Primary Key:
•Book has its own primary key (book_id), which is independent of Branch.

Located
Book Branch
at
1
4
E-R Diagram >> Relationship
Sets
Identifying Relationship Example
Entities:
1.Book:
Attributes: book_id (Primary Key), title.
2.BorrowedCopy:
1. Attributes: copy_id (Partial Key), borrow_date, book_id (Foreign Key).
Relationship:
Each borrowed copy is uniquely identified by its copy_id and the book_id it belongs to. If the
book is deleted, the borrowed copy record cannot exist.
Primary Key:
•BorrowedCopy’s primary key is a composite key: (book_id, copy_id).
ERD Representation:
•Relationship: Borrowed (double-lined diamond between Book and BorrowedCopy).

Located Borrowed
Book Borrowed
at Copy
1
4
E-R Diagram >> Relationship
Sets

Weak Entity
Identifying
relationship

Not
Identifying
1
5
E-R Diagram >> Relationship
Sets
Recursive Relationship Set – The same
entity set participates more than once in
the relationship.

 The function that an entity plays in a


relationship is called that entity’s role.
 Since entity sets participating in a
relationship set are generally distinct,
roles are implicit and are not usually
specified.
 However, they are useful when the
meaning of a relationship needs
clarification.
1
5
E-R Diagram >> Relationship
Sets

Parallel Relationship Set – more than


one relationships between the same Take
entity sets.
Students Courses

TA
1
6
E-R Diagram >> Mapping
Cardinalities
Mapping cardinalities, or Cardinality ratios, express the number of entities to which another entity can be
associated via a relationship set.

One-to-one(1:1) – An entity in A is
associated with at most one entity in B,
and an entity in B is associated with at
most one entity in A.

chair-
chairperson department
dept
1
7
E-R Diagram >> Mapping
Cardinalities
One-to-many (1:N) – An entity in A is
associated with any number of entities in
B. An entity in B, however, can be
associated with at most one entity in A.

faculty
faculty class
-class
1
7
E-R Diagram >> Mapping
Cardinalities
Many-to-One (M:1) – An entity in A is
associated with any number of entities in
B. An entity in B, however, can be
associated with at most one entity in A.
1
8
E-R Diagram >> Mapping
Cardinalities
Many-to-many (M:N) – An entity in A is
associated with any number of entities in
B, and an entity in B is associated with
any number of entities in A.

Works on

student enroll class


1
9
E-R Diagram >> Participation
Constraints
Total participation – Every member of the
entity set must participate in the
relationship.
Total participation is shown by a double line in the
ER diagram.

professor guides student


Partial participation – Not all entities in
the set are involved in the relationship.
In the previous example not every
professor guides student.
2
0
Extended E-R Diagram >>
Generalization
Generalization – It is the process of
extracting common properties from a
set of entities and create a generalized
entity from it.

It is a bottom-up approach in which tow or


more entities can be generalized to a
higher level entity if they have some
attributes in common.
2
1
Extended E-R Diagram >>
Specialization
Specialization – an entity is divided into
sub- entities based on their
characteristics.

It is a top-down approach where higher


level entity s specialized into two or
more lower level entities.
2
2
Extended E-R Diagram >>
Aggregation
Aggregation – an ER diagram is not
capable of representing relationship
between an entity and a relationship
which may be required in some scenarios.
In those cases, a relationship with its
corresponding entities is aggregated into
higher level entity.
Draw ERD guide

1. Identify the Entities -Every entity should be represented by a rectangle in the


diagram
2. Define Attributes for Each Entity-
• Identify the attributes that need to be stored for each entity.
• Primary Key (PK): Mark the unique identifier for each entity (usually underlined
in ERD). Composite type, derived type
3. Define Relationships Between Entities - Draw a diamond shape to represent the
relationship, and connect it to the related entities.
4. Determine Cardinality (Multiplicity) of Relationships –
• One-to-One (1:1)
• One-to-Many (1:N)
• Many-to-Many (M:N)
Use crow’s feet to represent "many" and a straight line to represent "one".
5. Identify Weak Entities (If Any) - A weak entity cannot exist without a
parent entity. Draw a double rectangle to represent a weak entity.
6. Identifying Relationship
• The child entity's primary key includes the primary key of the parent
entity as part of its own primary key.The child entity depends on the
parent for its existence. Without the parent, the child cannot exist.
• Represented by a double diamond in ER diagrams.
7. Non-Identifying Relationship
• How to Identify: The child entity’s primary key is independent of the
parent entity’s primary key.
The child entity can exist without the parent entity.
How to Represent:
Represented by a single diamond in ER diagrams.
2
3
E-R Diagram >> Practice 1 (Banking
Enterprise)
▸ The bank is organized into branches. Each branch is located in a particular city and is identified by a
unique name. The bank monitors the assets of each branch.
▸ Bank employees are identified by their employee-id values. The bank administration stores the name
and telephone number of each employee, the names of the employee’s dependents, and the
employee-id number of the employee’s manager. The bank also keeps track of the employee’s start
date and, thus, length of employment.
▸ Bank customers are identified by their customer-id values. The bank stores each customer’s name, and
the street and city where the customer lives. Customers may have accounts and can take out loans. A
customer may be associated with a particular banker, who may act as a loan officer or personal banker
for that customer.
▸ Accounts can be held by more than one customer, and a customer can have more than one account.
Each account is assigned a unique account number. The bank maintains a record of each account’s
balance, and the most recent date on which the account was accessed by each customer holding the
account.
▸ A loan originates at a particular branch and can be held by one or more customers. A loan is identified by
a unique loan number. For each loan, the bank keeps track of the loan amount and the loan payments.
Although a loan payment number does not uniquely identify a particular payment among those for all
the bank’s loans, a payment number does identify a particular payment for a specific loan. The date and
amount are recorded for each payment.
2
4
E-R Diagram >> Practice 2 (Company

Database)
The company is organized into departments. Each department has a unique name, a unique number,
and a particular employee who manages the department. We keep track of the start date when that
employee began managing the department. A department may have several locations.
▸ A department controls a number of projects, each of which has a unique name, a unique number, and
a single location.
▸ We store each employee’s name, social security number, address, salary, gender, and birth date. An
employee is assigned to one department but may work on several projects, which are not necessarily
controlled by the same department. We keep track of the number of hours per week that an
employee works on each project. We also keep track of the direct supervisor of each employee.
▸ We want to keep track of the dependents of each employee for insurance purposes. We keep each
dependent’s first
name, gender, birth date, and relationship to the employee.
Draw the E-R Diagram.
2
5
E-R Diagram >> Practice 3 (Online Book Store

Database)
Every book has a title, isbn, year and price. The store also keeps the author and publisher for any
book.
▸ For authors, the database keeps the name, address and the url of their homepage.
▸ For publishers, the database keeps the name, address, phone number and the url of their website.
▸ The store has several warehouses, each of which has a code, address and phone number. The
warehouse stocks several books. A book may be stocked at multiple warehouses. (In previous
sentence, we are not referring to a
particular copy of the book. Consider for example “the complete book” for our course. This book may be
stocked at
multiple warehouses.) The database records the number of copies of a book stocked at various
warehouses.
▸ The bookstore keeps the name, address, email-id, and phone number of its customers.
▸ A customer owns several shopping basket. A shopping basket is identified by a basketID and contains
several books. Some shopping baskets may contain more than one copy of same book. The database
records the number of copies of each book in any shopping basket.
Design an ER diagram for such a bookstore.
2
6
E-R Diagram >> Practice 4 (Blog Management
System)
Construct an ER diagram according to the details provided below:
▸ The blog management system maintains each blog writer’s unique email, name, encoded password,
gender, date of birth, join date, length of employment and address. The address field consists of three
components: postal code, city and street name. Every blog writer is hired by only one blog writer as
his employer. The visitors may follow more than one blog writer.
▸ Each of the blogs has blog id, details, date, time and category. One blog may fall under several
categories. Here blog id cannot uniquely identify a specific blog but blog id together with blog writer
email can uniquely identify a specific blog. A blog writer may publish several blogs.
▸ The visitors can see all the blogs published by writers. Each visitor can comment more than one time in
each blog and the system maintains the date, time, content of that blog comment. Visitors can also hit
reactions (like/dislike) in more than one blogs. The system maintains unique visitor email, visitor name
and encrypted password for each visitor.
2
7
E-R Diagram >> Practice 5 (League of
Villains)
Consider the following Scenario:
The League of Villains is getting more and more prominent. To reduce the dominance of
the villains, hero society is thinking of positioning heroes in regions. However they first
need to design a database with the following conditions:
▸ Heroes have a unique name, a power, strength level and a rank. Villains also have properties similar
to heroes. Also, each villains may have a boss who is also a villain himself.
▸ A hero is responsible for a certain region. A region has latitude, longitude, and population. A region
can be terrorized by multiple villains. However, one villain does not terrorize more than a region.
▸ Heroes and villains often fight. Hero society needs to keep track of the dates and results of
thesefights. A hero and a
villain may fight multiple times.

Design an ERD for the scenario.


2
8
E-R Diagram >> Practice 6 (Course Mgmt.
System)
Consider the following scenario for Course Management System:
▸ The university stores all the student information that includes a unique student id, name, date of
birth, address.
Address is stored in the following three sections: street name, postal code and city.
▸ Each course is identified by its unique course code, trimester, course name and course content. One
course is
conducted by several faculties and a student can choose several courses in a single trimester.
▸ The university identifies each faculty through their unique employee id. Each faculty also has a
particular room no, name, contact no, email and join date. Each faculty is associated with anonymous
reviews of students. Each review consists of a review id, review details and datetime. The review id
can’t identify a particular review among all the reviews but the review id for a specific faculty can
identify a particular review. Each student is also assigned to a specific faculty for advising purpose.

Design an ER Diagram for the scenario that satisfies all the given requirements.
2
9
E-R Diagram >> Practice 7 (Job Portal
System)
Consider the following scenario for a Job portal:
▸ The job portal manages each user’s profile where each user is represented by his or her name, unique
email, address, date of birth, educational qualifications, job position and job experience. Both recruiters
and job seekers are user and one recruiter can recruit more than one job seeker.
▸ The recruiters can post job openings to the job portal. The job portal keeps track of each posts date,
time, contents,
no of viewers. The system also keeps track of which job seeker is interested in which job posts.
▸ Each of the offices is maintained by their unique office id, name, address and contact no. Every user
belongs to some offices as a recruiter or, an employee or, a follower. Each person can provide his or
her anonymous review of offices. Each of the review contains review id, date, time, review details. The
review id cannot uniquely identify a particular review but a review id together with an office id can
uniquely identify a particular review.

Design and ER Diagram for the scenario that satisfies all the given requirements.

You might also like