42
ER - Model Professor (Healthcare ± IT), IIHMR - New Delhi. Prof. (Dr.) T. Muthukumar M.Sc; M.C.A; M.B.A; M.Phil;Ph.D

tm-ER Model

Embed Size (px)

Citation preview

Page 1: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 1/42

Page 2: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 2/42

Entity-Relationship Model

Entity Sets & Attributes

Relationship Sets

E-R Diagram

Constraints in ER 

Keys & Weak Entity Sets

Entity vs. Attribute

Summary of ER 

Symbols Used in E-R Notations

Page 3: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 3/42

Entity Sets

A databasedatabase can be modeled as:

 ± a collection of entities,

 ± relationship among entities.

An entityentity is an object that exists and isdistinguishable from other objects.

Example: specific person, company,

event, plant

Page 4: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 4/42

Entity Sets

Entities are described using attributesattributesEx: people have names and addresses

An entityentity setset is a set of entities of the same

type that share the same properties. Example: set of all persons, companies,

trees, holidays.

Page 5: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 5/42

Attributes

Entity is represented by a set of attributes,that is descriptive properties possessed by all

members of an entity set.

Example:customer = (customer-id, customer-name,

customer-street, customer-city)

loan = (loan-number, amount)

Page 6: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 6/42

Attributes

Keys: Minimal set of attributes whose

values uniquely identify an entity in the set

 ± Candidate Keys: all sets of attributes that

can potentially be a key.

 ± Primary Key: One of the candidate keys

is chosen to be a ³primary´ key.

Page 7: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 7/42

Relationship Sets

A relationshiprelationship setset is a mathematical relationamong n u 2 entities, each taken from entitysets

{(e1, e2, « en) | e1 E 1, e2 E 2, «, en

 E n} where (e1, e2, «, en) is a relationship

 ± Example: (Hayes, A-102) depositor 

There can be multiple relationship sets between the same two entities.

Page 8: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 8/42

Relationship Set borrower 

Page 9: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 9/42

E-R Diagrams

     Rectangles represent entity sets.

     Diamonds represent relationship sets.

     Lines link attributes to entity sets and entity sets to relationship sets.

     Ellipses represent attributes

     Underline indicates primary key attributes

Page 10: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 10/42

Ternary Relationships

Ternary relationships - used to record associations betweenthree entity sets.

Example: Each branch has several jobs that can be workedon by

 ± For this we need to record the association between employees, branches and jobs.

Page 11: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 11/42

Roles / Self Referential Relationships

Entity sets of a relationship need not bedistinct

The labels ³manager´ and ³worker´ arecalled rolesroles; they specify how employeeentities interact via the works-for relationship set.

Roles are indicated in E-R diagrams by

labeling the lines that connect diamonds torectangles.

Page 12: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 12/42

Page 13: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 13/42

Constraints in ER 

Key Constraints

Cardinality Constraints

Participation Constraints Overlapping Constraints

Coverage Constraints

Page 14: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 14/42

Key Constraints

Consider depositor relationship: A customer can deposit into manyaccounts; an account can have many depositors.

Compare with: Each department has at most one Manager 

Contrast with: Each customer can be the borrower on oneloan. However, each loan can have many borrowers.The restriction that each customer can be borrower on oneloan => K ey Constraint

Page 15: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 15/42

Key Constraint II

Relationship set like borrower - sometimes

said to be one-to-many Relationship set between customers and

accounts -> many-to-many

Page 16: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 16/42

Key Constraint III

Additional Restriction: a loan may be borrowed by onlyone customer -> one-to-one

Page 17: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 17/42

Key Constraints for Ternary Relationships

Key constraints in binary relationships can be

easily extended to ternary.

Page 18: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 18/42

Alternative Notation for Cardinality Limits

     Cardinality limits can also express participation constraints

Page 19: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 19/42

Participation Constraints

     Total participation (indicated by double/thick line): every entity in the entity set participates inat least one relationship in the relationship set

     E.g. participation of loan in borrower is total

     every loan must have a customer associated to it via borrower 

     Partial participation: some entities may not participate in any relationship in the relationship

set     E.g. participation of cu stomer  in borrower  is

 partial

      Not every cu stomer has a loan

Page 20: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 20/42

Participation Constraints

Page 21: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 21/42

Keys

A su per  su per keykey of an entity set is a set of one

or more attributes whose values uniquely

determine each entity.

A candidatecandidate keykey of an entity set is a

minimal super key

 ± C u stomer-id  is candidate key of 

cu stomer 

 ± account-number  is candidate key of 

account 

Page 22: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 22/42

Keys

Although several candidate keys may

exist, one of the candidate keys is

selected to be the primary primary keykey.

Page 23: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 23/42

Weak Entity Sets

Attributes associated with an entitycontain a key (to uniquely identify theentities)

An entity set that does not have a primarykey is referred to as a weak weak entityentity set  set .

Example:

 ± Employees can purchase policies to cover their dependents.

Page 24: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 24/42

Weak Entity Sets

Weak entity is uniquely identified by a

conjunction of some of its attributes and the

 primary key of another entity -- Identifying  Identifying 

entityentity set  set..

Page 25: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 25/42

Weak Entity Sets

Restrictions:

 ± It must relate to the identifying entity set via

a one-to-many relationship set from theidentifying to the weak entity set

  ± It must have total participation in the

identifying relationship set.

Page 26: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 26/42

Weak Entity Sets (Cont.)

We depict a weak entity set by double rectangles. We underline the discriminator of a weak entity set with

a dashed line.

payment-number  ± discriminator of the payment  entityset

Primary key for  payment  ± (loan-number, payment-number )

Page 27: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 27/42

Entity vs. Attribute

Remember ± attribute values are atomic

(cannot be broken down further)

Should addressaddress be an attribute of Employeesor an entity (connected to Employees by a

relationship)?

Depends upon the use of address information,

and the semantics of the data:

Page 28: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 28/42

Entity vs. Attribute

If we have several addresses per 

employee, address must be an entity

(since attributes cannot be set-valued).

If address is to be shared by manyemployees, address should be an

entity.

If the structure (city, street, etc.) isimportant, e.g., we want to retrieve

employees in a given city, address

must be modeled as an entity (since

attribute values are atomic .

Page 29: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 29/42

Entity vs. Attribute (Contd.)

Works_In2 does not

allow an employee to

work in a department

for two or more periods.

Similar to the problem of 

wanting to record several

addresses for an employee:

we want to record several  several 

val ues of the descriptiveval ues of the descriptiveattributes for each instanceattributes for each instance

of this relationship.of this relationship.

name

Employees

ssn lot

Works_In2

from todname

budgetdid

Departments

dname

budgetdid

name

Departments

ssn lot

Employees Works_In3

Durationfrom to

Page 30: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 30/42

Entity vs. Relationship

First ER diagram OK if a

manager gets a separate

discretionary budget for 

each dept.

What if a manager gets adiscretionary budget that

covers all managed

depts?

 ±  ±  RedundancyRedundancy of d budget,which is stored for each

dept managed by the

manager.

Manages2

name dname

budgetdid

Employees Departments

ssn lot

dbudgetsince

Employees

since

name dname

budgetdid

Departments

ssn lot

Mgr_Appts

Manages3

dbudget

apptnum

- Misleading: suggests dbudget

tied to managed dept.

Page 31: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 31/42

Binary vs. Ternary Relationships

agepname

DependentsCovers

name

Employees

ssn lot

Policies

policyid cost

Beneficiary

agepname

Dependents

policyid cost

Policies

Purchaser 

name

Employees

ssn lot

Consider Figure 1 - What

does it depict?

Additional constraints:

 ± A policy cannot be owned jointly by two employees

 ± Every policy must be owned

 by some employee

 ± Dependents is a weak entity

set - uniquely identified by policyId

Page 32: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 32/42

Binary vs Ternary

Constraint 1: Add a key constraint on Policieswith respect to Covers

  ± Side effect: policy can cover only one

dependent

Constraint 2: Total participation constraint onPolicies

  ± Ok if each policy covers at least onedependent

Constraint 3: Introduce an indentifyingrelationship set.

Page 33: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 33/42

Summary of ER 

Several kinds of integrity constraints can be

expressed in the ER model: key

constraints, participation constraints, and

overlap/ covering  constraints for ISAhierarchies. Some foreign key constraints

are also implicit in the definition of a

relationship set.

Page 34: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 34/42

Summary of ER 

 ±  Some constraints (notably, f unctional dependencies) cannot be expressed in the

ER model.

 ±  Constraints play an important role indetermining the best database design for 

an enterprise.

Page 35: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 35/42

Summary of ER 

ER design is subjective. There are often

many ways to model a given scenario!

Analyzing alternatives can be tricky,

especially for a large enterprise.Common choices include:

 ±  Entity vs. attribute, entity vs.

relationship, binary or n-aryrelationship, whether or not to use ISA

hierarchies, and whether or not to use

aggregation.

Page 36: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 36/42

Summary of ER 

Ensuring good database design: resultingrelational schema should be analyzed and

refined further.

Page 37: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 37/42

Symbols Used in E-R Notation

Page 38: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 38/42

Symbols Used in E-R Notations

Page 39: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 39/42

Alternative E-R Notations

Page 40: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 40/42

Database Management Systems

Page 41: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 41/42

And now

discussion

Page 42: tm-ER Model

8/3/2019 tm-ER Model

http://slidepdf.com/reader/full/tm-er-model 42/42

Database Management System

Contact:

Prof. (Dr.) T. Muthukumar 

[email protected]

tmkumar [email protected]

(0-9871969455)