CS34311 The Entity- Relationship Model Part II.. CS34312 Database Design Stages Application...

22
CS3431 1 The Entity- Relationship Model Part II.
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    225
  • download

    2

Transcript of CS34311 The Entity- Relationship Model Part II.. CS34312 Database Design Stages Application...

CS3431 1

The Entity-Relationship Model

Part II.

CS3431 2

Database Design StagesApplication

Requirements

ConceptualDesign

Logical Design

Physical Design

Conceptual Schema

Logical Schema

Physical Schema

CS3431 3

Relationship types in ER Model

Supplier

sName

sLoc

Consumer

cName

cLoc

Supply

price

Product

pName pNumber

qty

3-ary “supplies” relationship: Supplier supplies Products to Consumers

CS3431 4

Recursive Relationship Types and Roles

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

quantityContains

bike

Part

frame

wheel

seat

tire

1

2

1

1

CS3431 5

ER Model so far

Structures Entity Types Relationship Types

Binary, ternary, n-ary Recursive

Attributes For entity types and relationship types Simple, composite, multivalued

Roles

CS3431 6

ER Model: Key ConstraintsHow : Underline the key attribute/attributes

Key for Student is sNumber Student

sNumber

sName

Key for Movie is <title, year>Movie

title

year

Note:We can represent key for entity type consisting of more than 1 attribute (e.g.: Movie)We cannot represent multiple keys for an entity type (e.g: key for Student can be either sNumber or sName)

CS3431 7

ER Model: Cardinality Constraints

How : Expressed using (min, max)

Student

sNumber

sName

Course

cNumber

title

HasTaken

(2, 3) (0, *)

Student can take >= 2 and <= 3 CoursesCourse can have >= 0 and <= * (infinity) Students

min and max are non-negative integersmax > min

CS3431 8

Cardinality Constraints

1:1 relationship type: A Dept has exactly one Manager, A Person can manage at most one Dept

Person

pNumber

pName

Dept

dNumber

dName

Manages

CS3431 9

Cardinality Constraints

1:1 relationship type: A Dept has exactly one Manager, A Person can manage at most one Dept

Person

pNumber

pName

Dept

dNumber

dName

Manages(0, 1) (1, 1)

CS3431 11

Cardinality Constraints

1:many relationship type: A Person works for exactly one Dept, A Dept can have any number of Persons

Person

pNumber

pName

Dept

dNumber

dName

WorksFor

CS3431 12

Cardinality Constraints

1:many relationship type: A Person works for exactly one Dept, A Dept can have any number of Persons

Person

pNumber

pName

Dept

dNumber

dName

WorksFor

(1, 1) (0, *)

CS3431 13

Cardinality Constraints1:1 relationship type: A Dept has exactly one Manager, A Person can manage at most one Dept

1:many (1:n) relationship type: A Person works for exactly one Dept, A Dept can have any number of Persons

Person

pNumber

pName

Dept

dNumber

dName

Manages(0, 1) (1, 1)

Person

pNumber

pName

Dept

dNumber

dName

WorksFor

(1, 1) (0, *)

CS3431 15

Cardinality Constraints

many:many (m:n) relationship type: A Person works for one or more Depts, A Dept can have any number of Persons

Person

pNumber

pName

Dept

dNumber

dName

WorksFor

CS3431 16

Cardinality Constraints

many:many (m:n) relationship type: A Person works for one or more Depts, A Dept can have any number of Persons

Person

pNumber

pName

Dept

dNumber

dName

WorksFor

(1, *) (0, *)

CS3431 17

Cardinality Constraints for n-ary relationships

A Supplier supplies at least one Product to some Consumer

Supplier

sName

sLoc

Consumer

cName

cLoc

Supply

price

Product

pName pNumber

qty

CS3431 18

Cardinality Constraints for n-ary relationships

Supplier

sName

sLoc

Consumer

cName

cLoc

Supply

price

Product

pName pNumber

qty

(1, *) (0, *)

(0, *)

A Supplier supplies at least one Product to some Consumer

CS3431 19

Cardinality Constraints for n-ary relationships

Supplier

sName

sLoc

Consumer

cName

cLoc

Supply

price

Product

pName pNumber

qty

(1, *) (0, *)

(0, *)

What about the following constraints : (1) A Consumer gets a Product from only one Supplier(2) Each Supplier supplies exactly 2 Products

CS3431 20

Cardinality Constraints for Recursive Relationships

A Part can be subpart of one superPartA Part can have many subParts

Contains

Part

pName pNumber

subPartsuperPart

quantity

CS3431 21

Cardinality Constraints for Recursive Relationships

A Part can be subpart of one superPartA Part can have many subParts

Contains

Part

pName pNumber

subPartsuperPart

quantity

(0, 1)(0, *)

CS3431 22

Cardinality Constraints for Recursive Relationships

A Part can be subpart of one superPartA Part can have many subParts

A Part can be subpart of many superPartsA Part can have many subParts

C onta ins

P art

pN am e pN um ber

subP artsuperP art

quantity

(0 , 1 )(0 , *)

C onta ins

Part

pN am e pN um ber

subPartsuperPart

quantity

(0 , *)(0 , *)

CS3431 24

ER Model Constraints Summary

Key Constraints

Cardinality Constraints Expressed using (min, max) Binary relationship types are called 1:1, 1:many,

many:many

CS3431 25

Summary of ER Structures

Entity Types Relationship types – binary, ternary, n-ary.

recursive Attributes

For entity types or relationship types Simple, composite or multi-valued

Constraints – key, cardinality Roles of entity types in a relationship type ISA relationship types Weak Entity Types – identifying relationship

type, identifying entity type