9/2/2014 1yan huang - er chapter 6: er – entity relationship diagram major components of er...

44
06/11/22 1 Yan Huang - ER Chapter 6: ER – Entity Chapter 6: ER – Entity Relationship Diagram Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

Upload: charles-johnson

Post on 01-Apr-2015

236 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 1Yan Huang - ER

Chapter 6: ER – Entity Chapter 6: ER – Entity Relationship DiagramRelationship Diagram

Major components of ER diagramMajor components of ER diagram PracticesPractices

Page 2: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 2Yan Huang - ER

ERER

1976 proposed by Peter Chen1976 proposed by Peter Chen ER diagram is widely used in database ER diagram is widely used in database

designdesign Represent conceptual level of a database Represent conceptual level of a database

systemsystem Describe things and their relationships in high Describe things and their relationships in high

levellevel

Page 3: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 3Yan Huang - ER

Basic ConceptsBasic Concepts

Entity set – an abstraction of similar Entity set – an abstraction of similar things, e.g. cars, students things, e.g. cars, students An entity set contains many entitiesAn entity set contains many entities

Attributes: common properties of the Attributes: common properties of the entities in a entity setsentities in a entity sets

Relationship – specify the relations among Relationship – specify the relations among entities from two or more entity setsentities from two or more entity sets

Page 4: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 4Yan Huang - ER

An ExampleAn Example

Page 5: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 5Yan Huang - ER

RelationshipRelationship

A relationship may be thought as a set as A relationship may be thought as a set as wellwell For binary relationship, it enumerates the pairs For binary relationship, it enumerates the pairs

of entities that relate to each otherof entities that relate to each other For example, entity set For example, entity set M = {Mike, Jack, Tom}M = {Mike, Jack, Tom}

entity set entity set F = {Mary, Kate}.F = {Mary, Kate}. The relationship The relationship set set marriedmarried between M and F may be between M and F may be {<Mike,Mary>,<Tom, Kate>}{<Mike,Mary>,<Tom, Kate>}

Page 6: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 6Yan Huang - ER

RelationshipRelationship

A A relationship relationship setset is a mathematical relation is a mathematical relation among among nn 2 entities, each taken from entity 2 entities, each taken from entity setssets

{({(ee11, , ee22, … , … eenn) | ) | ee11 EE11, , ee22 EE22, …, , …, eenn EEnn}}

where (where (ee11, , ee22, …, , …, eenn) is a relationship) is a relationship Example: Example:

(Hayes, A-102) (Hayes, A-102) depositordepositor

Page 7: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 7Yan Huang - ER

Relationship ExampleRelationship Example

Page 8: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 8Yan Huang - ER

Attribute of A Relationship Attribute of A Relationship SetSet

Page 9: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 9Yan Huang - ER

RelationshipRelationship

The degree of a relationship = the number The degree of a relationship = the number of entity sets that participate in the of entity sets that participate in the relationshiprelationship Mostly binary relationshipsMostly binary relationships Sometimes moreSometimes more

Mapping cardinality of a relationshipMapping cardinality of a relationship 1 –11 –1 1 – many1 – many many – 1many – 1 Many-manyMany-many

Page 10: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 10Yan Huang - ER

One-One and One-ManyOne-One and One-Many

Page 11: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 11Yan Huang - ER

Many-one and many-manyMany-one and many-many

Page 12: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 12Yan Huang - ER

1- many1- many

Page 13: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 13Yan Huang - ER

Many - 1Many - 1

Page 14: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 14Yan Huang - ER

Many - manyMany - many

Page 15: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 15Yan Huang -CSCE4350 - ER

Alternative Cardinality Alternative Cardinality SpecificationSpecification

Page 16: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 16Yan Huang - ER

Note on Mapping Note on Mapping CardinalityCardinality

Both many and 1 include 0Both many and 1 include 0 Meaning some entity may not participate in the Meaning some entity may not participate in the

relationshiprelationship

Page 17: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 17Yan Huang - ER

Total ParticipationTotal Participation

•When we require all entities to participate in the relationship (total participation), we use double lines to specify

Every loan has to have at least one customer

Page 18: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 18Yan Huang - ER

Self RelationshipSelf Relationship

Sometimes entities in a entity set may Sometimes entities in a entity set may relate to other entities in the same set. relate to other entities in the same set. Thus self relationshipThus self relationship

Here employees mange some other Here employees mange some other employeesemployees

The labels “manger” and “worker” are The labels “manger” and “worker” are called called roles roles the self relationshipthe self relationship

Page 19: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 19Yan Huang - ER

More examples on self-More examples on self-relationshiprelationship

People to peoplePeople to people Parent – childrenParent – children Manager – employeeManager – employee Husband – wifeHusband – wife

Word to wordWord to word Root – synonymRoot – synonym

Page 20: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 20Yan Huang 350 - ER

AttributesAttributes

Both entity sets and relationships can Both entity sets and relationships can have attributeshave attributes

Attributes may beAttributes may be Composite Composite Multi-valued (double ellipse)Multi-valued (double ellipse) Derive (dashed ellipse)Derive (dashed ellipse)

Page 21: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 21Yan Huang - ER

Another ExampleAnother Example

Page 22: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 22Yan Huang - ER

KeysKeys

A A super keysuper key of an entity set is a set of one of an entity set is a set of one or more attributes whose values uniquely or more attributes whose values uniquely determine each entity.determine each entity.

A A candidate keycandidate key of an entity set is a of an entity set is a minimal super keyminimal super key

Although several candidate keys may Although several candidate keys may exist, one of the candidate keys is selected exist, one of the candidate keys is selected to be the to be the primary keyprimary key..

Page 23: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 23Yan Huang - ER

Key ExamplesKey Examples

Suggest super keys for the following Suggest super keys for the following entity?entity?

What are the candidate keys?What are the candidate keys? Primary key?Primary key?

author

name

birthday

death

description

Page 24: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 24Yan Huang - - ER

Ternary RelationshipTernary Relationship

Page 25: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 25Yan Huang - ER

Can We Decompose a Ternary Can We Decompose a Ternary Relationship?Relationship?

Some relationships that appear to be non-Some relationships that appear to be non-binary may be better represented using binary may be better represented using binary relationshipsbinary relationships E.g. A ternary relationship E.g. A ternary relationship parentsparents, relating a , relating a

child to his/her father and mother, is best child to his/her father and mother, is best replaced by two binary relationships, replaced by two binary relationships, fatherfather and and mothermother

Using two binary relationships allows partial Using two binary relationships allows partial information (e.g. only mother being know)information (e.g. only mother being know)

But there are some relationships that are But there are some relationships that are naturally non-binarynaturally non-binary

E.g. E.g. works-on, why?works-on, why?

Page 26: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 26Yan Huang - ER

Converting Ternary to Converting Ternary to binarybinary

In general, any non-binary relationship can be represented In general, any non-binary relationship can be represented using binary relationships by creating an artificial entity set.using binary relationships by creating an artificial entity set. Replace Replace R R between entity sets A, B and Cbetween entity sets A, B and C by an entity set by an entity set EE, ,

and three relationship sets: and three relationship sets:

1. 1. RRAA, relating , relating E E and and A A 2. 2.RRBB, relating , relating E E and and BB

3. 3. RRCC, relating , relating E E and and CC Create a special identifying attribute for Create a special identifying attribute for EE Add any attributes of Add any attributes of R R to to E E For each relationship (For each relationship (aaii , b , bii , c , cii) in ) in R,R, create create

1. a new entity 1. a new entity eeii in the entity set in the entity set E E 2. add (2. add (eeii , a , ai i ) to ) to RRAA

3. add (3. add (eeii , b , bii ) to ) to RRBB 4. add ( 4. add (eeii , c , ci i ) to ) to RRCC

Page 27: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 27Yan Huang - ER

Converting Ternary to Converting Ternary to binarybinary

Page 28: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 28Yan Huang - ER

Design an ER DiagramDesign an ER Diagram

Design a database for an on-line reservation Design a database for an on-line reservation system for microscopes in material science system for microscopes in material science lablab

There are two types of users: microscope There are two types of users: microscope administrators and microscope end usersadministrators and microscope end users

Each microscope is located in a specific labEach microscope is located in a specific lab Each request is assigned to an administrator Each request is assigned to an administrator

who can authorize or deny the requestwho can authorize or deny the request Using of some microscope requires the Using of some microscope requires the

presence of an administratorpresence of an administrator Time is divided into 1 hour slots. Each Time is divided into 1 hour slots. Each

reservation can only take one or more time reservation can only take one or more time slotsslots

Page 29: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 29Yan Huang - ER

Weak Entity SetWeak Entity Set

Some entity sets in real world naturally Some entity sets in real world naturally depend on some other entity set depend on some other entity set They can be uniquely identified only if They can be uniquely identified only if

combined with another entity setcombined with another entity set Example:Example:

section1, section2, … become unique only if section1, section2, … become unique only if you put them into a context, e.g. csce4350you put them into a context, e.g. csce4350

Page 30: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 30Yan Huang - ER

Weak Entity Set NotationsWeak Entity Set Notations

Double rectangles for weak entity set

Double diamond for weak entity relationship

Dashed underscore for discriminator

Page 31: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 31Yan Huang - ER

SpecializationSpecialization

A lower-level entity set inherits all the A lower-level entity set inherits all the attributes and relationship participation of attributes and relationship participation of the higher-level entity set to which it is the higher-level entity set to which it is linked.linked.

A lower-level entity set may have A lower-level entity set may have additional attributes and participate in additional attributes and participate in additional relationshipsadditional relationships

Page 32: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 32Yan Huang - ER

Page 33: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 33Yan Huang - ER

SpecificationSpecification

DisjointDisjoint CompletenessCompleteness constraintconstraint (use double (use double

lines)lines) totaltotal : an entity must belong to one of the : an entity must belong to one of the

lower-level entity setslower-level entity sets partialpartial: an entity need not belong to one of : an entity need not belong to one of

the lower-level entity setsthe lower-level entity sets

Page 34: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 34Yan Huang - ER

Design ConsiderationsDesign Considerations

Use of entity sets vs. attributesUse of entity sets vs. attributes Whether we want to keep additional Whether we want to keep additional

informationinformation Use of entity sets vs. relationship setsUse of entity sets vs. relationship sets

Actions among entities are usually represented Actions among entities are usually represented by relationshipsby relationships

Binary versus Binary versus nn-ary relationship sets-ary relationship sets N-nary relationships are usually more natural N-nary relationships are usually more natural

for actions among entity setsfor actions among entity sets Weak entity set vs. strong entity setWeak entity set vs. strong entity set GeneralizationGeneralization

Page 35: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 35Yan Huang - ER

NotationsNotations

Page 36: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 36Yan Huang - ER

NotationsNotations

Page 37: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 37Yan Huang - ER

ER Practice AgainER Practice Again

Design an ER diagram for an online music Design an ER diagram for an online music store. The database will contain at least store. The database will contain at least the following concepts: songs, artists, the following concepts: songs, artists, bands, albums, and genres. bands, albums, and genres.

State your design assumptions you make State your design assumptions you make to support design decisions. Be sure your to support design decisions. Be sure your assumptions are reasonable.assumptions are reasonable.

Page 38: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 38Yan Huang CE4350 - ER

Best Practice Guide for ER Best Practice Guide for ER DesignDesign

Use of entity sets vs. attributesUse of entity sets vs. attributes Use of entity sets vs. relationship setsUse of entity sets vs. relationship sets Binary versus Binary versus nn-ary relationship sets-ary relationship sets Weak entity set vs. strong entity setWeak entity set vs. strong entity set

Choose the natural oneChoose the natural one GeneralizationGeneralization

If specialized entities need to keep additional If specialized entities need to keep additional information and participate in additional information and participate in additional relationshipsrelationships

Page 39: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 39Yan Huang - ER

ER for Banking EnterpriseER for Banking Enterprise

Description handhoutDescription handhout

Page 40: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 40Yan Huang - ER

Read ER DiagramsRead ER Diagrams

Following are some ER diagrams grabbed Following are some ER diagrams grabbed from the webfrom the web

Read to understand/criticizeRead to understand/criticize

Page 41: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 41Yan Huang - ER

??

?

??

?

?

?

?

Page 42: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 42Yan Huang -CSCE4350 - ER

? ? ?

?

?

Page 43: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 43Yan Huang -CSCE4350 - ER

?

Page 44: 9/2/2014 1Yan Huang - ER Chapter 6: ER – Entity Relationship Diagram Major components of ER diagram Major components of ER diagram Practices Practices

04/11/23 44Yan Huang -CSCE4350 - ER