+ All Categories
Home > Documents > The Entity-Relationship Model

The Entity-Relationship Model

Date post: 18-Mar-2016
Category:
Upload: hester
View: 26 times
Download: 1 times
Share this document with a friend
Description:
The Entity-Relationship Model. Instructor: Mohamed Eltabakh [email protected]. Database Design Stages. Application Requirements. Conceptual Design. ER Model. Conceptual Schema. Logical Design. Relational Model. Logical Schema. Creating tables in a DBMS. Physical Design. - PowerPoint PPT Presentation
Popular Tags:
25
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh [email protected]
Transcript
Page 1: The Entity-Relationship Model

1

The Entity-Relationship Model

Instructor: Mohamed Eltabakh [email protected]

Page 2: The Entity-Relationship Model

2

Database Design StagesApplication

Requirements

ConceptualDesign

Logical Design

Physical Design

Conceptual Schema

Logical Schema

Physical Schema

ER Model

Relational Model

Creating tablesin a DBMS

Page 3: The Entity-Relationship Model

3

Conceptual Design What is Conceptual Design?

Concise representation of the DB application requirements

Why Conceptual Design ? It helps to understand application requirements better It helps to communicate our understanding of application It helps to come up with a ‘good’ design

Page 4: The Entity-Relationship Model

Example: Banking System There are customers, each customer has some attributes:

customer-id, customer-name, customer-street, customer-city. The bank offers loans to customers, where each loan has a

loan-number, and the amount of the loan A customer can borrow multiple loans from the bank, but each

loan can be borrowed by only one customer.

4

This big story is captured in a better way using an ER model

Page 5: The Entity-Relationship Model

5

Conceptual Design (Cont’d) Conceptual Models

ER (Entity-Relationship) Model, Our focus UML (Unified Modeling Language), ORM (Object Role Modeling), etc.

ER Model Structures: Entities and Relationships Constraints

An ER schema is represented using Entity-Relationship Diagram (ERD)

Page 6: The Entity-Relationship Model

Modeling A database can be modeled as:

Collection of entities, Relationship among entities.

An entity is an object that exists and is distinguishable from other objects. Example: a person, company, event, bank account, store, etc. Entities have attributes

Example: a person has name, address, SSN, …

An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees, holidays

6

Page 7: The Entity-Relationship Model

7

ER: Entity Sets and Attributes Entity set : Represent a set of “objects” Attribute: property of an entity, has a domain In ER diagram

Entity set rectangle Attribute Oval.

Student

sNamesNumber

sAge

Entity Set Studentwith attributes (sNumber, sName, sAge)

Page 8: The Entity-Relationship Model

Example: University SystemWhat entity sets come to your mind…

8

Student

ProfessorBuilding

Employee

Course

Classroom

Page 9: The Entity-Relationship Model

Attributes Types Primitive attributes: Attribute stores a single value (Number,

String, Boolean, Date, …)

Composite attributes: An attribute can be divided into sub-attributes (each is primitive)

Multi-values attributes: Attribute with many values

Derived attributes: Attributes computed from others

9

Student

sNamesNumber

sAge

These are primitive attributes

DoB

Page 10: The Entity-Relationship Model

10

Complex AttributesComposite Attribute: address Multivalued Attribute: major

major

sta testree t

address

city

Derived Attribute: Age

Age

Student entity setwith all its attributes

Student

sNam esN um ber

sAge

m ajor

sta testree t

address

city

Age

DoB

Page 11: The Entity-Relationship Model

Expand Your Design: University System

Add attributes for each entity set

11

Student

sN am esNum ber

sA ge

m ajor

statestreet

address

city

Student

Professor

Building

Employee

Course

Classroom

Name Address

Establishing Year

Page 12: The Entity-Relationship Model

12

Relationship Types Relationship: Association (connection) between entities sets Relationship Type: Class of relationships Representation: Use a diamond shape

Student

sNumber

sName

Course

cNumber

title

HasTaken

Relationship type HasTaken to represent Courses taken by Students

Page 13: The Entity-Relationship Model

13

Relationships with Attributes

Student

sNumber

sName

Course

cNumber

title

HasTaken

project

Relationship HasTaken has an attribute project which is theproject the Student did for the Course

Student

sNumber

sName

Course

cNumber

title

HasTaken

A relationship may have attributes These attributes do not belong to any of the connected entities. But

they belong the relationship

Page 14: The Entity-Relationship Model

14

Example I (Simple Application)

Suppliers have a name, and location.Products have a name, price, and number.Consumers have a name, and location.

Suppliers supply products on certain dates, while consumers buy products of certain quantity

How would you model this application? a) What are the entities and attributes? b) What are the relationships?

Page 15: The Entity-Relationship Model

Modeling of Example I

15

supplier

sName

sLoc

consumer

cName

cLoc

product

pNumber sName sPrice

supplies buys

date quantity

This ER captures exactly what is written in text>> It is wrong to add “date” or “quantity” to one of the entity sets

Page 16: The Entity-Relationship Model

16

Example II (More Complicated)

Suppliers have a name, and location.Products have a name, and number.Consumers have a name, and location.

Some Suppliers have established contracts to supply a certain Product to a particular Consumer for specially negotiated price at a given quantity.

How would you model this application?

Page 17: The Entity-Relationship Model

17

Modeling of Example II

Supplier

sName

sLoc

Consumer

cName

cLoc

Supply

price

Product

pName pNumber

qty

Model the relationship Supplier supplies Products to Consumers

Ternary relationship(three-way)

Page 18: The Entity-Relationship Model

Binary vs. Multi-way Relationships

18

supplier

sName

sLoc

consumer

cName

cLoc

product

pNumber sName

supplies buys

price quantity

Binary relationship

Page 19: The Entity-Relationship Model

19

ER Model so far Entities and entity sets

Relationships Binary, ternary, multi-way

Attributes For entity sets and relationship types Simple, composite, multi-valued, derived

Page 20: The Entity-Relationship Model

20

Entities with Different Attribute Types (Recap)

Composite Attribute: address

Multivalued Attribute: major

major

sta testree t

address

city

Derived Attribute: Age

Age

Student entity typewith all its attributes

Student

sNam esN um ber

sAge

m ajor

sta testree t

address

city

Age

DoB

Primitive Attribute: sNumber

sNumber

Page 21: The Entity-Relationship Model

Binary Relationships (Recap)

21

supplier

sName

sLoc

consumer

cName

cLoc

product

pNumber sName sPrice

supplies buys

date quantity

Attributes can be attached to Entity Sets or Relationships

Page 22: The Entity-Relationship Model

22

Multi-Way Relationships (Recap)

Supplier

sName

sLoc

Consumer

cName

cLoc

Supply

price

Product

pName pNumber

qty

Model the relationship Supplier supplies Products to Consumers

Ternary relationship(three-way)

Page 23: The Entity-Relationship Model

23

Recursive Relationship Types and Roles

Refer to the same entity set in the relationship

Recursive relationship type : Part-Subpart

Roles: There are Parts that play the role of superPartThere are Parts that play the role of subPart

Contains

Part

pName pNumber

subPartsuperPart

quantity

If two entities in the same entity set have a relationship Recursive relationship

Page 24: The Entity-Relationship Model

Recursive Relationships: Another Example

24

Employees & Managers

Employee

ID

Name

Supervisesupervisor

supervised

Page 25: The Entity-Relationship Model

What about an Exercise: University System

Lets enrich this initial design…

25

Student

sN am esNum ber

sA ge

m ajor

statestreet

address

city

Student

Professor

Building

Employee

Course

Classroom

Name Address

Establishing Year


Recommended