Top Banner
Entity Relationship Model Entity: A thing of interest in the real world (e.g. employee, product) Attribute: A property of the entity (e.g. salary, sex, birthdate) - atomic attribute - composite attribute (e.g. Name(FirstName, MI, LastName, Suffix), BirthDate(M,D,Y))
31

Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

May 23, 2018

Download

Documents

lamnhi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Entity Relationship Model

• Entity: A thing of interest in the real world (e.g. employee, product)

• Attribute: A property of the entity (e.g. salary, sex, birthdate) - atomic attribute - composite attribute (e.g. Name(FirstName, MI, LastName, Suffix), BirthDate(M,D,Y))

Page 2: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

• Value: an instance of an attribute for a particular entity (e.g. Employee(SSN, Sex, Bdate) ⇓ ⇓ ⇓

481-33-1766 F 2/17/66 value of the attribute ‘sex’

*single valued attribute *multivalued attribute – set of values (unordered sets) (e.g. Phones = {Business-phone, home-phone, cell-phone) *composite attributes – sturctured fields (name)

• Domain of an Attribute the set of values that may be assigned to the attribute

Page 3: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Graphical Presentation of Entities

SSN

Employee

Sex Salary

Address

BDate

Phones

Name

FirstN MI LastN

Suffix

Entity

Attribute

Composite Attribute

Page 4: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Relationship An association among Entities E1 … En by the n-tuple Rel (E1 …, En) Or graphically as:

E1

E2

En

Rel

Works for

ChairedBy

Employee Dept

Dept #

Name

Main office

SSN Name

Phone BDate

For example:

Page 5: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Degree of Relationship

⇒number of participating entity sets

Majority Parent

Minority Parent

Joint Venture Child

Joint venture

Ternary Relationship

Page 6: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Relationships

An entity can participate multiple timer in a relationship:

Employee SSN

Name

BDate Sex

SupervisedBy

The semantics of

the Relationship are defined by the Role

Names

superviser

supervisee

Page 7: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Relationships

A relationship can be represented as an attribute ( and vice versa)

Department

Employee SSN

Name Email BDate

Sex

ID# Name Main

Office

Budget

Works in

Chaired by

Department

ID # Name office Manager

email Manager SSN

Manager Phone

Employee

name BDate email

Dept No

Sex SSN

Dept No

Dept No

Mgr Name

Dept Name

Page 8: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Relationships

A relationship can be represented as an attribute (and vice versa)

Department

Employee SSN

Name Email BDate

Sex

ID# Name Main

Office

Budget

Works in

Chaired by

Department

ID # Name office Manager

email Manager Name

Manager Phone

Employee

name BDate email

Dept No

Sex SSN

Dept No

Dept No

Mgr SSN

Dept Name

Page 9: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Relationships

A relationship can be represented as an attribute (and vice versa)

Department

Employee SSN

Name Email BDate

Sex

ID# Name Main

Office

Budget

Works in

Chaired by

Department

ID # Name office Manager

email Manager Name

Manager Phone

Employee

name BDate email

Dept No

Sex SSN

Dept No

Dept No

Mgr SSN

Dept Name

Page 10: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Language Analogy

Entities = Nouns

Attributes = Adjectives

Relationships = Verbs

Page 11: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Language Analogy

Entities = Nouns

Attributes = Adjectives

Relationships = Verbs

??? = Adverbs

Page 12: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Attributes of relationships (Adverbs)

Project

Employee SSN

Name Email BDate

Sex

ID# Name Main

Office

Budget

mulid

Works On Hrs-Week

Page 13: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Entity Type (schema)

STUDENT

SSN BDATE SEX

Entity Instance

STUDENT1 M

1-39-75

985-12-1789

STUDENT2 F

10-26-55 321-41-1786

NAME

John Doe

Sally Smith

Page 14: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Entity Sets

STUDENT1 M

985-12-1789

STUDENT2

321-41-1786

F

1-39-75 10-26-55

BDATE SEX SSN NAME

Sally Smith John Doe

Page 15: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

WEAK ENTITY SETS

Employee1

Adam Sandler 35

481.. Employee2 372..

53 David Smith

Dependent Of

Dependent1 Dependent2 Dependent3

5 F 8 F 5 F Sue Doe Sally Smith Sally Smith

Employee

Dependent

Entity

sets

Identify relashinship : Relashionship through which weak entity set can be uniquely identified

Identifying Owner : Entity that allows for unique id

Page 16: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

WEAK/STRONG ENTITY SETS

Dependent

Name Age Sex Relation

Sally Smith

Johny Smith

Sue Doe

Billy Doe

Sally Smith

5

3

1

8

5

F

M

F

M

F

Daughter

Son

Daughter

Son

Daughter

Page 17: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

E-R Terminology

SUPERKEY ATTRIBUTES:

A Set of attributes that allows us to identify an entity uniquely

(eg : Name, Address…)

CANDIDATE KEYS: minimal superkeys

(I.e. no proper subset is a superkey){ SSN, Names – superkey

SS = candidate key}

PRIMARY KEY :

Candidate key chosen as principal identifier for the entity (e.g. SSN)

Page 18: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

WEAK/STRONG ENTITY SETS

Dependent

Name Age Sex Relation

Sally Smith

Johny Smith

Sue Doe

Billy Doe

Sally Smith

5

3

1

8

5

F

M

F

M

F

Daughter

Son

Daughter

Son

Daughter

SSN

480-34-0771

192-76-3879

862-33-0112

114-39-3728

033-69-8791

Primary Key

Page 19: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

WEAK/STRONG ENTITY SETS

Dependent

Name Age Sex Relation

Sally Smith

Johny Smith

Sue Doe

Billy Doe

Sally Smith

5

3

1

8

5

F

M

F

M

F

Daughter

Son

Daughter

Son

Daughter

If Primary Key exists => Strong Entity Set

If Primary Key does not exist => Weak entity Set

Primary key

Page 20: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

WEAK ENTITY SETS

Employee1

Adam Sandler 35

481.. Employee2 372..

53 David Smith

Dependent Of

Dependent1 Dependent2 Dependent3

5 F 8 F 5 F Sue Doe Sally Smith Sally Smith

Employee

Dependent

Entity

sets

Identify relashinship : Relashionship through which weak entity set can be uniquely identified

Identifying Owner : Entity that allows for unique id

Page 21: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

EMPLOYEE

OFFICE

MAPPING CONSTRAINTS

WORKS IN ROOM

1:1 ( one to one)

D. Yarowsky G. Hager S Smith

NEB 328 NEB 215 NEB 324

Page 22: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

MAPPING CONSTRAINTS

EMPLOYEE

SUPERVISES

SPOUSE

WIFE

SUPERVISER SUPERVISEE

HUSBAND

John Smith Sue Weller Sally Smith

Grace Jones Danny Jones Sally Jones

1:1 ( one to one) Relationship mapping does not need to

be total

Page 23: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

MAPPING CONSTRAINTS (cardinality constraints)

N:1 (many-to-1)

DEPARTMENT

EMPLOYEE

WORKS FOR 1

N

ACCOUNTING

MARKETING SALES

John Smith Sue Weller Adam Weller

Sally Smith Danny Jones Jane Doe

E1

889-26-6789 12/85 John Doe

Name Bdate SSN

Page 24: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

MAPPING CONSTRAINTS (cardinality constraints)

N:1 (many-to-1)

DEPARTMENT

EMPLOYEE

WORKS FOR 1

N

ACCOUNTING

MARKETING SALES

John Smith Sue Weller Adam Weller

Sally Smith Danny Jones Jane Doe

E1

889-26-6789 12/85 John Doe

Name Bdate SSN

Page 25: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

MAPPING CONSTRAINTS (cardinality constraints)

N:M (many – many)

PROJECT

EMPLOYEE

WORKS ON N

M

PROJECT 3

PROJECT 2 PROJECT 1

John Smith Sue Weller Adam Weller

Sally Smith Danny Jones Jane Doe

E1

889-26-6789 12/85 John Doe

Name Bdate SSN

Page 26: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Employee

Dependent Of

Dependent

N

PARTICIPATION CONSTRAINT

Total Participation:

-> Candidate for representation as an

attribute

=> Existence Dependency (I.e. dependent in database without sponsoring employee)

1

Page 27: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Specialization

• Notation that avoids duplication of entity structure

• Inheritance of attributes checking account- ISA -account saving account - ISA -account interest bearing- ISA -checking account • Important in object-oriented model design

Page 28: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

AGGREGATION

Employee

MACHINERY

PROJECT

User

Worker On

ID

name number hour

ID Name

Page 29: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

AGGREGATION

Employee

MACHINERY

PROJECT

User

Worker On

ID

name number hour

ID Name

Page 30: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,

Dependent

EMPLOYEE

PROJECT DEPARTMENT

Project Name

Project number

Name

Name

Name

Head offices DEPT#

Last Name

B Date

Address

Customer Type

Salary

Age

SSN

First name

MI Relation

Sex

Page 31: Entity Relationship Model - Department of Computer …yarowsky/cs415slides/2-ERModel1.pdfEntity Relationship Model • Entity: A thing of interest in the real world (e.g. employee,