Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the...

57
Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally & Aisha AlArfaj Rev. by L. Fatimah Alhayan 1 Ref. Chapter11 College of Computer and Information Sciences - Information Systems Dept. IS220 : Database Fundamentals

Transcript of Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the...

Page 1: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Lecture3: Data Modeling Using the Entity-Relationship Model.

Prepared by L. Nouf Almujally & Aisha AlArfajRev. by L. Fatimah Alhayan

1

Ref. Chapter11

Colle

ge o

f Com

pute

r and

Info

rmat

ion

Scie

nces

-In

form

atio

n Sy

stem

s Dep

t.

I S 2 2 0 : D a t a b a s e F u n d a m e n t a l s

Page 2: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

The Process of Database Design

Lect

ure3

2

Conceptual Design

Logical Design(Relational

Model)Physical Design

Page 3: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Conceptual Database Design

• ER Diagram is used.• Does not include implementation details.• Users and developers can easily understand and discuss.• Used to ensure all user requirements are met.• Enable designers to concentrate on specifying the

properties of the data, without being concerned aboutstorage details.

Lect

ure3

3

Page 4: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

ER Overview• The Entity-Relationship (ER) model is a popular high-level

conceptual data model.

• Based on a perception of a real world that consists of a collection of basic objects, called entities, and of the relationships among these objects.

• The ER model can be directly translated into relational tables.

• The Entity-Relationship Diagram (ERD) is a graphical model for representing the conceptual model for the data.

• E/R models the DB using three element types:- Entities- Attributes- Relationships

Lect

ure3

4

Page 5: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Example of ER Diagram

Lect

ure3

5

Page 6: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Entities and AttributesThe ER Model describes data as entities, relationships and attributes.➢1- Entity:

• The basic object that the ER model represents is an entity, which is a “thing” in the real world with an independent existence.

• Could be an object with a physical existence (student, car) or conceptual existence (company, course).

• Each entity has attributes.

➢Rectangles represent entities

Lect

ure3

6Student

Page 7: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Entity Types• Entity type: set of entities of the same type with the same basic

attributes are grouped or typed into an entity type.

• For example, the Student entity type

• More Example:7

Lect

ure3

Student

Course

Student1ID

name

Student2ID

name

Student3ID

name

book Doctor

ID

name

Page 8: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

An entity will have a value for each of its attributes;e.g. A specific student entity may have Name=‘Nora”, Age = 21, ID = 1111 ...etc.

e1

Name = Nora

Age = 21

ID =1111

The attribute values that describe each entity become a part of the data stored in the database.

Entities with values of their attributes

Lect

ure3

8

Page 9: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Entities and Attributes➢ 2- Attribute:

• Property describing an entity.• E.g. Student name, age, ID ,...etc.

➢ Oval represent attributes

Lect

ure3

9

st_name

Student

Page 10: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

• Simple:• An attribute that has a single atomic value with an

independent existence.• E.g. ID, Salary, Gender

• Composite:• An attribute composed of multiple components, each of

which represent more basic attributes with independent meaning.

• Composite attribute indicated with sub ovals.• E.g. Name (FirstName, MiddleName, LastName).

ID

Types of Attributes - Simple Versus Composite

Lect

ure3

10

STUDENT

St_noname DOB

Tel_no

FirstName MiddleName LastNameArea_cd

no

EX

Page 11: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Types of Attributes - Simple Versus Composite

• Composition may form a hierarchy where some components are themselves composite.

• The value of a composite attribute is the concatenation of the values of its simple attributes.

Lect

ure3

11

Page 12: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

• Single-valued:• An attribute that holds one single value for a single entity.• E.g. ID.

• Multi-valued:• An attribute that holds multiple values for the same entity.• use double line• E.g:

• colors attribute for a car - {Color} • College degrees attribute for a person - {college degree}.

Color

ID

Types of Attributes - Single-Valued Versus Multivalued

Lect

ure3

12

Page 13: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

• Stored:• E.g. Birth_date.

• Derived:• An attribute that represents a value that is derivable from the value

of a related attribute or set of attributes• derived attributes use dotted line• For Example:

• The age can be determined from the current date and the value of the birth date of a person, so:

age is a derived attribute and birth_date is a stored attribute.• Total_cost is derived from quantity*unit_price

Birth_date

Age

Types of Attributes - Stored Versus Derived

Lect

ure3

13

Page 14: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

• Some attribute values can be derived from related entities;• e.g. an attribute Number_of_employees of a DEPARTMENT entity can

be derived by counting the number of employees related to that department.

Types of Attributes - Stored Versus Derived

Lect

ure3

14

Employee Departmentworks-on

No_of_employee

ID

name Dept_No

Dept_Name

Page 15: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Keys of Entity

• Candidate Key: is a minimal set of attributes whose values uniquely identify an entity in the set. It cannot contain NULL

• There could be more than one candidate key; if so, we select one of them as the primary key and the other will be an Alternate Key

Element ( Symbol , name , atomic_no)

15

Lect

ure3

Primary Key Alternate Key

Candidate Key

Page 16: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Keys of Entity• Primary Key

• The candidate key that is selected to uniquely identify an entity type.• primary key attribute indicated with underline

• Choice of Primary Key (PK) is based on:• Attribute length• Number of attributes required• Certainty of uniqueness

• PK’s may be • simple PK (single attribute)

• CUSTOMER (custno, ….)• STUDENT (ID, …..)

• composite PK (multiple attributes) • ORDERLINE (orderno, prodno, quantity,…) 16

Lect

ure3

Page 17: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Drawing Entities and Attributes

• Rectangles represent entities• Oval represent attributes • derived attributes use dotted line• multi-valued attributes use double line• primary key attribute indicated with underline• Composite attribute indicated with sub ovals.

Lect

ure3

17

student

stu_id name dobage

phone

address

street city

Page 18: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Lect

ure1

18

Page 19: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Relationship• Association between two (or more) entities• Relationships represented by diamond

Examples• Students Register for Subjects• School Has Staff• Driver Commits Traffic Offence• Customer Orders Product• Supplier Supplies Parts To Projects

• Relationship type (relationship set)• Set of similar associations among entity sets.

Lect

ure3

19

ENTITY Relationship ENTITYattribute

attribute

primary key

Page 20: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Attributes of Relationship TypesRelationship types can also have attributes.• E.g. customer orders a product

• quantity is attribute of orders relationship

• E.g. Employee WORKS-ON Project• To record the number of hours per week that an employee works

on a particular project. The attribute Hours can be included to the WORKS-ON relationship type.

Lect

ure3

20

customer productorders

quantity

Employee Projectworks-on

Hours

Page 21: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Types of Relationships• Degree of relationship: is the number of entity types

that participate in it• UNARY – between entities from one entity set • BINARY – between entities from two entity sets • N-ARY – among entities from more than two entity

sets

Lect

ure3

21

Page 22: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

22

Unary(Recursive) Relationship• Unary relationship is a relationship type where the

same entity type participates more than once in a different role.

• It is a Recursive relationship.

Employee

Supervises

ER M

odel

Page 23: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Oe 1

Oe 2

Oe 3

Oe 4

Oe 5

Oe 6

Oe 7

EMPLOYEE

r1

r2

r3

r4

r5

r6

SUPERVISION

21

1 2

2

1

1

12

1

2

2:

:

Relationship Degree - Unary relationship

Lect

ure3

23

Page 24: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

24

Roles• Role indicates the purpose that each participating entity

type plays in a relationship. (e.g. prerequisite, requester)

COURSE

require

requester prerequisite

ER M

odel

Page 25: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

25

Roles• Role can be used when two entities are associated through

more than one relationship to classify the purpose of each relationship.

STAFF

allocated

Manager

Staff member

BRANCH

Branch office

Branch office

manages

ER M

odel

Page 26: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

26

Relationship Degree - Binary relationship

• A relationship of degree two (2 entity types) are binary.

DepartmentWorks forEmployee

ER M

odel

Page 27: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

O

O

O

O

O

O

O

e1

e2

e3

e4

e5

e6

e7

EMPLOYEE

r1

r2

r3

r4

r5

r6

r7

WORKS_FOR

d1O

d2O

d3O

DEPARTMENT

:

:

:

Relationship Degree - Binary relationship

Lect

ure3

27

Page 28: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

28

Relationship Degree - Ternary relationship

• A relationship of degree three (3 entity types) are ternary.

e.g. Supplying a part to a project by a supplier.

ProjectSupplySupplier

Part

ER M

odel

Page 29: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

s1 O

Os2

SUPPLIER

p1

p2

O

O

Op3

PART

r1

r2

r3

r4

r5

r6

r7

SUPPLY

j1

j2

j3

O

O

O

PROJECT

:

:

:

:

Relationship Degree - Ternary relationship

Lect

ure3

29

Page 30: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

UNARY : One entity set, recursive.

BINARY : Two entity sets linked (mostly used).

TERNARY :Three entity sets linked.

SUBJECT prerequisite

N

M

STUDENT SUBJECTenrolls inM N

RENTAL SHOP VIDEOownsM N

BORROWER

1

Relationship Degree

Lect

ure3

30

Page 31: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Example Relationships

31

Lect

ure3

Page 32: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Constraints on Relationships • There are two types of relationship constraints:

• Cardinality ratio.• Participation.

Lect

ure3

32

Page 33: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Cardinality RatioCardinality ratio Express the number of relationship an entity can participate in.

Relationships can be classified as :➢one-to-one (1:1)➢one-to-many (1:M) ➢Many-to-one (M:1)➢many-to-many (M:N)

Lect

ure3

33

Page 34: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

One-to-one Relationship (1:1)Professor Manage Department

P1 r1 D001P2P3 r2 D002

Each professor manages at most one department; and each department is managed by only one professor

Lect

ure3

34

Professor DepartmentManage11

Page 35: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

One-to-Many Relationship (1:M)Professor teach Section

P1 r1 3C01r2 3C03

P2 r3 3C02

Each professor teaches many sections; but each section is taught by only one professor (or at most one professor)

Lect

ure3

35

Professor SectionteachM1

Page 36: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Many-to-One Relationship (M:1)Professor work-in Department

P1 r1 Com. ScienceP2 r2 Network P3 r3 Info. Sys

Each professor works in only one Department; but each Department has many professors (many professors work in one department)

Lect

ure3

36

Professor DepartmentWork-in1M

Page 37: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Many-to-Many RelationshipStudent Enroll-in CourseS1 r1 is300S2 r2 is400S3 r3 is500S4 r4 is600

Each student can enroll in many courses; and each course can be enrolled by many students.

Lect

ure3

37

Student courseEnroll-inMM

Page 38: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

MultiplicityMultiplicity is the number (range) of possible entities that may relate to a single association through a particular relationship

• Takes the form (min#, max#)

Lect

ure3

38

Page 39: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Professor Manage DepartmentP1 r1 D001P2 P3 r2 D002

• Each Professor may manage 0 to 1 department,• Each Department should be managed by only one Professor .

Multiplicity

Lect

ure3

39

Professor Departmentmanage(0,1) (1,1)1 1

Page 40: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

MultiplicityProfessor teach Section

P1 r1 3C01P2 r2 3C03 P3 r3 3C02

• Each Professor may teach 0 to 5 Sections,• Each Section should be taught by only one Professor .• * = many .. Use it if the number is not specified

Lect

ure3

40

Professor SectionteachM1

(0,5) (1,1)(0,*)

Page 41: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

MultiplicityStudent Enroll-in CourseS1 r1 is300S2 r2 is400S3 r3 is500S4 r4 is600

• Each student should enroll in 1 to 7 Courses,• Each Course may be enrolled by 0 to 100 students.• * = many .. Use it if the number is not specified

Lect

ure3

41

Student CourseEnroll-inMM

(1,7) (0,100)(1,*) (0,*)

Page 42: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Participation• Participation constraints determine whether all or only some

entities participate in a relationship.

• Two type of participation:• Mandatory (Total)• Optional (Partial) Le

ctur

e3

42

Page 43: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Participation• Optional (partial) (0:*) if an entity’s existence does not

require a corresponding entity in a particular relationship. (Not existence-dependent).

• eg, an employee may not have a spouse• not every staff manages a departmentPartial participation is represented by single line

• Mandatory (total) (1:*) if an entity’s existence requires the existence of an associated entity in a particular relationship (existence-dependent). • eg, every spouse must be that of an employee• Every department is managed by some staff.Mandatory participation is represented by double line

Lect

ure3

43R E

R E

Page 44: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Examples

Lect

ure3

44

employee spouse1 1

has

(0,M) (1,1)

(1:M) (0:N)

ORDERCUSTOMER place

SUBJECTSTUDENT enrol

1 N

M N

Page 45: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Lect

ure1

45

Page 46: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Strong & Weak Entity Type• A strong entity type is an entity that have a key attribute.

(I.e. It exists independently of other entity types)

• A weak entity type is an entity that does not have a key attribute. (I.e. Its existence depend on some other entity type)

• The entity type which the weak entity type depends on is called the identifying entity type (owner).e.g EMPLOYEE

• Weak entities are identified by the combination of:• A partial key of the weak entity type.• The primary key of the owner entity type.

Lect

ure3

46

Page 47: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Representing Weak Entities and Relationships• Weak entity is indicated by a double line rectangle, and weak

relationship is represented by a double line diamond.

• Participation of weak entity in weak relationship is always mandatory.

Lect

ure3

47

Employee DependentHas1 M

Page 48: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Weak Entity TypeThe relationship between the weak entity and its owner entity is called weak relationship.• Eg: Employee Has Dependent

• Dependent can be regarded as a weak entity—only when the attributes of Dependent can not uniquely identify a dependent. Eg, Dependent has the attributes d_name and d_birthdate only, but two employees may have dependents with the same name and date of birth. However employee_no and d_name uniquely identify each dependent.

• Employee is the owner entity

• Has is the weak relationship

Lect

ure3

48

Page 49: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

EMPLOYEE

SSN Salary

DEPENDENT

Name Sex

BDate Relationship

DEPENDENTS-OF

1 N

Weak Entity Type

Lect

ure3

49

Page 50: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Modelling with E-R Diagram• List the major entity sets in the system• Represent the entity sets graphically by a rectangle• Search for relationships between the entities and represent

them graphically by a diamond• Add attributes, underline PK attribute/s• Model relationship cardinality and participation Le

ctur

e3

50

Page 51: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

TOTAL PARTICIPATION OF E2 in R

CARDINALITY RATIO 1:N FOR E1:E2 IN E

STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R

Symbol

E 2

R E 2

R (min,max) E

N

RE 1

E 11

Summary of Notation For ER-Diagrams

Lect

ure3

51

Page 52: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Example (Company)The COMPANY database keeps track of a company’s employees,departments and projects.

The company is organized into departments. Each departmenthas a unique number, name, several locations , and a particularemployee who manages the department. We keep track of thestart date when that employee began managing thedepartment.Each department may control many projects. However, Eachproject should be controlled by one department only. Projecthas a unique number, name, and a single location.

Lect

ure3

52

Page 53: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Example (Company)We store each employee’s name, social security number,address, salary, sex, and birth date. An employee should beassigned to one department only but each department musthave many employees.Each employee should work on several projects and each projectshould run by many employees. We keep track of the number ofhours 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 forinsurance purposes. We keep each dependent’s first name, sex,birth date, and relationship to the employee.

Lect

ure3

53

Page 54: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Lect

ure3

54

Page 55: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Tool For Drawing ER Diagrams In Oraclesoftware

Lect

ure3

55

Page 56: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

Lect

ure1

56

Page 57: Lecture3: Data Modeling Using the Entity-Relationship Model.Lecture3: Data Modeling Using the Entity-Relationship Model. Prepared by L. Nouf Almujally& Aisha AlArfaj Rev. by L. Fatimah

References• “Database Systems: A Practical Approach to Design,

Implementation and Management.” Thomas Connolly, Carolyn Begg. 5th Edition, Addison-Wesley, 2009.

Lect

ure2

57