0% found this document useful (0 votes)
42 views44 pages

3 ER Diagram

A department may have many employees but an employee works for only one department.

Uploaded by

Gulbahar
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)
42 views44 pages

3 ER Diagram

A department may have many employees but an employee works for only one department.

Uploaded by

Gulbahar
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/ 44

ER MODEL

1
CONTENT
■ ER MODEL DEFINITION
■ ENTITY
■ ATTRIBUTES
■ RELATIONSHIP
■ SYMBOLS
■ CARDINALITIES

2
Database Design
 Requirements gathering and specifications
– provide you with a high-level understanding of
– the organization,
– its data, and
– the processes
that you must model in the database.

 Database design
− involves constructing a suitable model of this information.

 Types of DB Design
1. Conceptual Design/Logical Design- ER model
2. Physical design- Relational model

3
Conceptual Database Design
 Modeling the collected information at a high-level
 without using a particular DBMS.

 The most popular database design language is the


Entity-relationship model proposed by Peter Chen in 1976.

4
Relation Instances

5
Relation Instances
Relation Instances

ER Model
ER Model Example

7
ERD Design Steps
1. Find the Entities from the problem statement
(Look for Nouns)

2. Find Attributes of each Entity


(adjectives -
describing features of entity)

3. Find the Relationships between the entities.


(Check for Verbs)

8
Entity Sets
■ An entity in an ER model is a thing in the real world, can be
– Physical (e.g. person, animal, place)
– Conceptual (e.g. event, company, job, university course)
stored as a record or a table row
Example: specific person, company, event, plant

 An entity set is a set of entities of the same type that share the same
properties.
stored as a relation or a table
Example: set of all persons, companies, trees, holidays

9
Entity
Entity
 Represents a group of real-world objects that have properties.
 Does not always have to be a physical real-world object such as a
person or department,
 it can be an abstract concept such as a project or job.
 Stored as a relation or a table
 Example: Person (Employee, Student), Department(Sales, Accounts
D), Place(Hospital, University), object or event, Project

Entity instance
 is a particular example or occurrence of an entity type.
 Ex: entity : Employee(Eid, Ename, Esal),
 entity instance (1, ‘Hulk’, 5000).

10
1. Representing Entity
 Entity are represented by rectangles with the name of the entity
in the rectangle.

 Examples:

 An entity name is normally a singular NOUN.


Person instead of People, Project instead of Projects

 First letter of each word in the entity name is capital

Find the Entities from the problem statement (Look for Nouns)
11
2. Relationship

Relationship
• is a set of meaningful associations/ connections among entities
• Each relationship is given a name that describes its function.
• Example:
• Employee works on Project, Teacher teaches Subject,
• Customer owns Account, Customer buys Cake, Doctor treats Patient

Relationship instance
is a particular occurrence of a relationship that relates entity instances.
Ex, WorksOn - relationship
Relationship instance : ‘Tony Stark' works on project ' End Game ‘
or (Tony Stark, End Game).
12
Representing Relationship Types

A simple relationship between two entities is represented as a


named diamond that connects the two entity types.

Name

Find the Relationships between the entities.


(Check for Verbs –
Make sentence using 2 Entities)

13
Attributes
Property of an entity or a relationship.
Ex, entity Employee has attributes: name, salary, title, etc.
Represented as named ellipse

Rules:
1. attribute names begin with a lower case letter.

2. Each attribute has a domain which is


the set of allowable values for the attribute.
14
Attributes Types
2. Find Attributes of each Entity
(adjectives - describing features of entity)

 Attributes may be

 Simple/ Single valued attribute (ellipse)

 Composite attribute (hierarchy of ellipses)

 Multi-valued attribute (double ellipse)

 Derived attribute (dashed ellipse)


15

02/23/202
Attributes Types (contd…)
A. Simple attribute
 contains a single part.
 Also called atomic attributes.
– Example, salary.
Represented by an ellipse

B. Composite attribute
 consists of multiple components (subattributes) each.
– Ex: address consists of (street, city and state)
– Name consists of (?,?,?)
 Represented as
 hierarchy of ellipses
– splitting of the ellipse
into component ellipses
16
Attributes Types (contd…)
Composite Attributes

17
Single-Valued and Multi-Valued
Attributes
A. Single-valued attribute
consists of a single value for each entity instance.
Example: salary

B. Multi-valued attribute
 Attribute may have multiple values for a single entity instance.
 Ex:
a) Telephone number =(home phone number, cell phone number, etc.)

b) Degree=(ATHE, BSc Computing, MSc-IT)


 Represented as a double ellipse
Name

18
Derived Attributes
Derived attribute
 Its value is calculated from other attributes
 Its value is not physically stored.
Name
 Represented by dashed ellipse

Example :
a) Age can be calculated from DOB

b) Percentage obtained can be calculated from all Subject Marks


c) Total_Price_products_purchased can be found using
UnitPrice and QuantityOrdered

19
Keys
 A candidate key is a minimal set of attributes that uniquely
identifies each instance of an entity type.
 For example, the number attribute uniquely identifies an
Employee and is a candidate key for the Employee entity type.
 A primary key is a candidate key that is selected to identify each
instance of an entity type.
 The primary key is chosen from a set of candidate keys. For
instance, an employee may also have EmiratesID as an
attribute. The primary key may be either EmiratesID or number
as both are candidate keys.
 A composite key is a key that consists of two or more attributes.
 For example, a course is uniquely identified only by the course
code (22C) and the course number within the department (144).
identify the type of attributes
Example

22 Yan Huang - ER

02/23/202
Attributes in the ER Model Example

23
Class Activity
■ Draw an E-R Diagram for the following
statement. “Players has team and they
participated games.” / “Customer buys
novel creates by writer.”

24
■ ER
SYMBOL
S

25
ERD Design Steps
1. Find the Entities from the problem statement
(Look for Nouns)

2. Find Attributes of each Entity


(adjectives -
describing features of entity)

3. Find the Relationships between the entities.


(Check for Verbs)

26
Step 4: Relationship Cardinalities
■ Relationship cardinalities or multiplicities
■ multiplicity –
number of possible occurrences of an entity that
may relate to a single occurrence of an associated
entity.

(Q1: 1 instance of First entity is related to


how many Instances of second entity
Ans: One Employee WorksFor ONE Department (Put 1 besides Department)
Q2: 1 instance of Second Entity is related to
how many instances of First Entity)
Ans: One Department has many Employees (Put N besides Employee)
■ There are 4 common types:
– ONE-TO-ONE (1:1)
– ONE-TO-MANY (1:* OR 1:N)
– MANY-TO-ONE (*:1 OR M:1)
– MANY-TO-MANY (*:* OR N:M) 27
Mapping Cardinalities

One to one One to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
28
Mapping Cardinalities

Many to one Many to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
29
a. One-to-One Relationships
 In a one-to-one relationship,
 each instance of an entity class E1
can be associated with
 at most one instance of another entity class E2
 and vice versa.
 Example: A department may have only one manager, and
a manager may manage only one department.

30
a. One-to-One Relationship
Example

A department may have only one manager.


A manager (employee) may manage only one department.

31
b. One-to-Many Relationships
■ each instance of an entity E1 can be associated with
■ more than one instance of another entity E2.

■ However, E2 can only be associated with


– at most one instance of entity E1.

■ Example: A department offers many courses, but


a course is offered by only one department.

32
b. One-to-Many Relationship
Example

A project may be associated with at most one department.


A department may have multiple projects.

33
c. Many-to-Many Relationships

■ each instance of an entity E1 can be associated with


■ more than one instance of another entity E2
■ and vice versa.

■ Example: An employee may work on multiple projects, and


a project may have multiple employees working on it.

34
c. Many-to-Many Relationship
Example

35
37
■ ER
SYMBOL
S

38
ERD Design Steps
1. Find the Entities from the problem statement
(Look for Nouns)

2. Find Attributes of each Entity


(adjectives - describing features of entity)

3. Find the Relationships between the entities.


(Check for Verbs –
Make sentence using 2 Entities)

4. Find the cardinalities of the Relationships between the entities.


(Q1: 1 instance of First entity is related to
how many Instances of second entity
Ans: One Employee WorksFor ONE Department (Put 1 besides Department)
Q2: 1 instance of Second Entity is related to
how many instances of First Entity)
39
Ans: One Department has many Employees (Put N besides Employee)
An Example

40

Yan Huang - ER
02/23/202
Class Activity
■ Draw an E-R Diagram for the following
statement. “Players has team and they
participated games.” / “Customer buys
novel creates by writer.”

41
ER Design TASK
■ Construct an ER Model for a university database where:
– Each student has an id, name, birth date, and Grade /mark.

– Each professor has a name and is in a department.


– Each department offers courses and has professors. A department has
a name and a building location.
– Each course has a name and number and may have multiple sections.
– Each section is taught by a professor and has a section number.
– Students enroll in sections of courses. They may only enroll in a course
once (and in a single section). Once a student completes a course, they
receive a grade.

42
Task 2.a

■ Construct an ER Model for an Electronics


shop database which stores sales and customer
information
■ The database may includes the following
table.
■ Sales, Customer, Product, Supplier, Order,
Promotion, Staff , Department etc.

43
REFERENCES:
 Connolly, T.M. and Begg, C.E. (2015) Database systems: a practical
approach to design, implementation, and management. Pearson
Education.

 Coronel, C. and Morris, S. (2016) Database systems: design,


implementation, & management. London. Cengage Learning

 Elmasri, R. and Navathe., S.B., (2016). Fundamentals of Database


Systems, 7th Edition. New Jersey: Pearson.

 Teorey, T. (2011) Database Modelling and design: logical design.


Burlington: Elsevier

You might also like