ERD diagram and MS ACCESS file

profileRnieves0411
EntityRelationshipDiagramERD.pdf

1

Database Schema Design

Using Entity-Relationship Approach

(ER Approach or ER Model)

Tok Wang Ling National University of Singapore

2

Topics

ER Model 2

 Concepts/Constructs in ER Approach and diagram o Cardinality vs. Participation Constraint o Weak Entity Type, EX/ID Relationship Types, generalization

and specialization o Some extensions: Aggregation, Multiple FDs Representation

 English Sentence Structure and ER Diagram o self study

 ER Construct Notation Comparison  Database Schema Design using ER Approach  Translation of a (Normal Form) ER Diagram to a RDB  A Normal Form for ER Diagram

333

• ER approach was proposed by Prof. Peter Chen in TODS 1, 1976. • Main Concepts:

- entity (i.e. object) - relationship - attribute

Brief ideas: English correspondence

noun  entity verb  relationship Ref:

• Peter Chen paper TODS 1976 • Elmasri&Navathe’s book • Korth’s book • Hawryzkiewycz’s book

Person Person (entity)

John (entity) Mary

Married to

husband (role) wife (role)

(relationship)

ER Model

444

Entity: An entity is an object which exists in our mind and can be distinctly identified.

Q: How to identify entities?

E.g. - Ng Hong Kim with NRIC S0578936I - Account# 563978 of DBS Bank - Car with car plate number SBG 3538P

Entity type - Entities can be classified into different types. - Each entity type contains a set of entities each

satisfying a set of predefined common properties.

E.g. Employee, Student, Car, House, Bank Account

Q: What are the common properties of each of the above entity types?

ER Model

5

List of common entity types:

• People: humans who carry out some function Employees, students, customers

• Places: sites or locations Cities, offices, routes, countries

• Things: tangible physical objects Equipments, products, buildings

• Organizations Teams, suppliers, departments

• Events: things that happen to some other entity at a given date and time or as steps in an ordered sequence.

Employee promotions, project phases, account payments

• Concepts: intangible ideas used to keep track of business or other activities.

Projects, accounts, complaints ER Model

666

Relationship. A relationship is an association among several entities.

E.g. A relationship which associates customer Ng Hong Kim identified by NRIC S0578936I and DBS bank account 5075610.

Relationship type (or Relationship set) Each relationship type contains a set of relationships of the same type each satisfying a set of predefined common properties.

If E1 , E2 , …, En are entity types, then an n-ary relationship type R is a subset of the Cartesian Product E1 

E2 

… 

En ,

i.e. R 

E1 

E2 

… 

En or R 

{(e1, e2, …, en) | ei 

Ei , i = 1,2,…,n}

where (e1 , e2 , …, en ) is a relationship. When n = 2 (or 3), we call R a binary (or ternary) relationship type.

E.g. We define a binary relationship type Work to denote the association between two entity types Department and the Employee

Work 

Department 

Employee

777

Attribute • An entity type E (or a relationship type R) has attributes

representing the structural (static) properties of E (or R resp.).

• An attribute A is a mapping from E (or R ) into a Cartesian Product of n values sets, V1 

V2 

… 

Vn .

• If n 

2 , then we call attribute A a composite attribute, otherwise (i.e. when n=1) call it a simple attribute. E.g. DATE is a composite attribute with values sets

DAY, MONTH, YEAR

• The mapping can be one-to-one (1:1), many-to-one (m:1), one-to-many (1:m), many-to-many (m:m).

• If an attribute A is a 1:1 or m:1 mapping from E (or R) into the associated value sets, then A is called a single valued attribute, otherwise it is called a multivalued attribute.

ER Model

8ER Model 8

Note the difference between type and instance. We use o entity type vs. entity o relationship type vs. relationship o attribute vs. attribute value

Some books and papers use slightly different terms: o entity and entity instance o relationship and relationship instance o attribute and attribute value

Some books and papers just don’t differentiate them, simply use entity and relationship for both type and instance, may have interpretation problem.

999

Entity-Relationship Diagram (ER Diagram or ERD) • The structure (i.e. schema) of a database organized

according to the ER approach can be represented by a diagrammatic technique called an Entity-Relationship diagram. Notation: - entity type 

rectangle - relationship type 

diamond - attribute 

ellipse

m : 1 (single valued attribute) m : m (multi-valued attribute) 1 : 1 (one to one attribute) 1 : m (one to many attribute)

EMP work PROJ m m

Emp# Name Qual %effort BudgetProj#

Cardinality Cardinality

Note: There are some other different representations (notations). Many books don’t use arrows and have problem to interpret ER diagrams precisely.

Notations

101010

Different cardinalities of binary relationship types

Emp Deptwork n 1 FD: Emp  Dept

work is a many to one relationship type

Mgr Deptmanage 1 1 FDs: Mgr  Dept

Dept  Mgr

manage is a one to one relationship type

Emp Projectwork n n No FD between Emp and Project,

work is a many to many relationship type.

Q: What are the intuitive meanings of the above relationship types?

ER Model

111111

Composite Attribute

Identifier of entity type - A minimal set of attributes K of an entity type E which defines

a one-to-one mapping from E into the Cartesian Product of the associated value sets of K is called a key of E.

- One of the keys of an entity type is designed as the identifier. Q: How to choose the identifier of an entity type? E.g.. Registration#, NRIC#, and {P1, P2} are 3 keys of PATIENT entity type, we

choose Registration# as the identifier. Why?

Patient

E1 E2 E3

P1

P2

Day Month

Year

Surname Given name

Registration#

NRIC#

Date

Name

E123

Note: A line joining the two attributes’ arrows indicates the two attributes form a key of the entity type Patient.

E.g. P1 and P2 form a key of Patient.

Q: Are the concepts of identifier of entity type and primary key of relation of relational model the same? If not, what are the main differences between them?

E.g. Name, Date, and E123 are composite attributes.

121212

Identifier of relationship type • Let K be a set of identifiers of some entity types participating

in a relationship type R. K is called a key of the relationship type R if there is an 1:1mapping from R into the Cartesian Product of the associated value sets of K and no proper subset of K has such property.

• One of the keys of R is designated as the identifier of R.

Q: Why do we need to define identifiers for relationship types? How?

E.g. {Emp#, Proj#} is the only key of the relationship type “ work” in the previous EMP-PROJ ER diagram.

E.g.

Staff# is the identifier of the binary relationship type Belong.

Prof Belong Deptm 1

Staff# Name D# Dname

131313

Recursive relationship type

minor-part

PART

Bill-Of- material

Major-part m m

role name

ManagesSTAFF Superior

Subordinate

role name

1

m

Q: How to represent recursive relationship type and in a relational database?

Two relationship types between the same set of entity types

Person

live-in

own

House

1

m

m

m

Q: How to represent these 2 relationship types in a relational database? 

141414

Q: What are the differences between cardinality and participation constraint? Which one is better (i.e. more powerful)?

TakesStudent Course 2:8 4:m

Here 2:8 means each student must take at least (minimum) 2 courses and at most (maximum) 8 courses.

4:m means each course must have minimum 4 students and no maximum limit. (m means many, no limit).

Participation Constraint - another way to specify constraints:

If every entity of an entity type must participate in some relationship(s) of the relationship type then that entity type has total (or mandatory) participation in the relationship type.

If some entities of an entity type need not participate in any relationship of the relationship type then the participation of that entity type in the relationship type is partial (or optional).

E.g. Students take courses

151515

Ternary relationship type

SPJ PhoneOwner

Provider

1 n

1

SPJ ProjectPart

Supplier

m m

m

FD: Phone Owner, Provider

FD: Part, Project  Supplier

RB C

A

1

1 1

SPJ ProjectPart

Supplier

m m

1

No FDs among Part, Supplier, and Project. It is a m:m:m ternary relationship type.

FDs: A  B C B  A C C  A B

ER Model

1616

Subtype relationship (IS-A hierarchy) Living

Creature

IS-A

Person

IS-AIS-A

Male Person

Female Person

Set-operation relationships

Person

Male Person

Female Person

Union

Joint Appointment (E&B) Faculty

Business FacultyFaculty

Intersection

Eng

IS-A relationship is the same as the sub-class relationship in OO

Person

Male Person

Female Person

Another notation

Note the directions of the arrows.

171717

Decomposition relationship type

Professor

Associate ProfessorsFull Professors

By Rank

Assistant Professors

Note the directions of the arrows.

ER Model

181818

Existence-dependency (EX) relationship type and weak entity type

E.g.

The existence of a Child entity depends on the existence of an associated EMPLOYEE entity. Thus, if an Employee entity is deleted, its associated Child entities are also deleted.

The dependent entity type Child is a weak entity type (represented by a double rectangle), and Employee is a regular entity type.

Relationship type which involves a weak entity type is called existence- dependency relationship type (denoted with “EX” together with a relationship type name).

Child

NRIC

Name

DOB

Sex

EX Has Child

Employee

FD: NRIC Name, DOB, Sex

Note: An EX relationship type is a 1:m (one to many) relationship type.

Note: NRIC is the identifier of the entity type Child.

Note the directions of the arrows.

1919

Identifier-dependency (ID) relationship type • An entity cannot be identified by the value of its own

attributes, but has to be identified by its relationship with other entity. Such a relationship is called identifier- dependency relationship. E.g.

Note: By the original definitions, an identifier-dependency relationship type (denoted by ID) is also an existence-dependency relationship type. However, we should not just indicate an ID as EX.

Child DOB

Sex

ID Has Child

Employee

Given_name

E#

FD: E#, Given_name DOB, Sex

Q: What are the differences between this ER diagram and the previous page’s ER diagram.

Note: The Child has no NRIC attribute.

Note: The line on the arrow to the attribute Given_name indicates this attribute together with the identifier of Employee (i.e. E#) form the identifier of the weak entity type Child. So, we have:

Note: ID dependency relationships occur in XML data quite often.

Note the directions of the arrows.

202020

Another example of Identifier-dependency relationship type

country

province

city

ID

ID

Note: Different provinces of a country may have cities with the same name. So, city name cannot be used to identify a city.

E.g. City Waterloo, Ontario, Canada City Waterloo, Iowa, US City Waterloo, Illinois, US

Q: What are the identifiers of the entity types province and city?

ER Model

2121

Generalization and Specialization • Generalization is the result of taking the union of two or more

(lower level) entity types to produce a higher level entity type. • Specialization is the result of taking a subset of a higher-level

entity type to form a lower-level entity type. • Generalization is the same as UNION.

Specialization is the same as ISA. • In generalization, every higher-level entity must also be a lower-

level entity. Specialization does not have this constraint.

Note: There are other types of accounts, e.g., AUTOSAVE account and Fixed Deposit account.

(Specialization)

Account

Acct#

Name

Balance

ISA ISA

Fixed-deposit Checking-Account

Interest-rate Overdraft limit

Start-date

Maturity-date

2222

• Generalization is used to emphasize the similarity among lower-level entity types and to hide their difference. Specialization is the inverse, i.e. to highlight the special properties of the lower level entity types.

• The attributes of the higher-level entity types are to be inherited by lower-level entity types.

Another notation (Bad! Why?)

E.g. Staff

Acad-Staff Nonacad-Staff

UNION

(Specialization) (Generalization) (use thick lines)

Account

Saving-A Checking-A

Staff

Acad-Staff Nonacad-Staff

ISA ISA

(Generalization)

ER Model

232323

Some extensions to the ER approach (1) The ER approach does not allow relationships among relationships.

E.g. In an EMPLOYEE database, we want to describe information about employee who work on a particular project and use a number of different machines doing that work. Using the basic ER approach, we may have the ER diagram.

Q: Can we combine the 2 relationship types into one?

Machinery

Employee ProjectWork

Uses

Note: The constraint between the two relationship types Work and Uses is not captured explicitly in the above ER diagram.

Q: How do we capture this constraint in an ER diagram?

242424

• One solution is use aggregation. Aggregation is an abstraction through which relationships are treated as higher-level entities.

In the ER diagram, we treat the relationship type Work and the entity types Employee and Project as a higher-level entity type called Work. My better notation:

Note: The constraint is explicitly captured by the 2 ER diagrams, i.e.

Uses [Employee, Project] Work

(not a good notation)

Machinery

Employee ProjectWork

Uses

Machinery

Employee ProjectWork

Uses

Note: The line joining the diamond of the “Uses” relationship type and the aggregation does not touch the diamond of the “Work” relationship type.

252525

(2) We introduce a new construct called composite for constructing complex objects (complex entities) from some other simple and/or complex objects. The complex object and its component objects are not necessarily type (or object) compatible.

E.g.

Note: COMPOSITE is similar to IS-PART-OF relationship but not exactly the same.

Note: An apartment may have other components, e.g. kitchen.

Bed-Room

Apartment

Bath-Room

IS-PART-OF IS-PART-OF

E.g..

Bed-Room

Apartment

Bath-Room

COMPOSITE

Kitchen Living-Room

262626

(3) Represent more than one FD in a relationship type (using more than one set of cardinalities).

There are 2 FDs in the relationship type Take:

Student, Subject 

Teacher Teacher 

Subject

E.g. Student

Subject

Take

Teacher

m/-

m/1 1/m

Note: “-” means the entity type is not involved the respective set of cardinalities.

ER Model

272727

Hospital

Staff Doctor

1

Hospital Lab

Doctor Lab

Doctor Patient

ID Test

Assigned OccupancyWardStaff

Patient Test

Ward

Staff

ID Patient

Diagnosis Patient Test

Diagnosis

m

m m

1

m

m

m m

1 1 1

m m

1 1

m

m

ID Hospital Wards

Figure: Entity-relationship diagram for medical database. (from Tsichritzis’s book)

Q: Why ID?

282828

Figure: An Entity-relationship diagram.

Note: The relationship type EMP_DEP can be EX or ID depending on whether DEPENDEMT has identifier or not.

Q: Is there any constraint between SUPP-PART and SUPP_PART_PROJ ? Ans: Yes. Q: What is the constraint?

EMPLOYEE PROJECT

DEPARTMENT

DEPENDENT

DEPT_EMP

EX or ID

EMP_DEP

PROJ_WORK

PROJ_ MANAGER

SUPP_ PART_PROJ

PART

PART_ STRUCTURE

SUPP_PART

SUPPLIER1

m

1

m

m

1

m

m

m

m m

mm

mm

292929

EMPLOYEE PROJECT

DEPARTMENT

DEPENDENT

DEPT_EMP

EX or ID

EMP_DEP

PROJ_WORK

PROJ_ MANAGER

SUPP_ PART_PROJ

PART

PART_ STRUCTURE

SUPP_PART

SUPPLIER1

m

1

m

m

1

m

m

m

m

m

m

m

m

Constraint shown by the aggregation is:

SUPP_PART_PROJ [SUPPLIER, PART] 

SUPP_PART [SUPPLIER, PART]

(A better solution)

ER Model

303030

English Sentence Structure and ER Diagram (self study)

Ref: Peter P Chen. English Sentence Structure and Entity-Relationship Diagrams. 1983 Inf Sci 29(2-3) :127-149.

In order to construct a database using an ER diagram, the database designer not only has to interview users but also must study the system specification documents which are written in some natural language, such as English.

Some guidelines/rules for translating English sentences into ER diagrams are presented below:

Guideline 1: A common noun (such as student and employee) in English corresponds to an entity type in an ER diagram:

common noun entity type

Note: Proper nouns are entities not entity types, e.g. John, Singapore, New York City.

ER Model

313131

Guideline 2: A transitive verb in English corresponds to a relationship type in an ER diagram:

transitive verb relationship type

E.g. A person may own one or more cars and a car is owned by only one person.

person 1 mowns car

Guideline 3: An adjective in English corresponds to an attribute of an entity type in an ER diagram:

adjective attribute of entity type

O

Note: The cardinalities of person and car in the owns relationship type are 1 and m respectively, and the participation of person in the owns relationship type is optional (or partial) participation as some people may not own any car. Alternatively, we can have the participation constraints of person and car as 0:m and 1:1 respectively. Since a car must have an owner, the participation of car in the owns relationship type is mandatory (or total) participation.

Note: A transitive verb must have an object.

E.g. A London supplier, a red part, a male person.

323232

Guideline 4: An adverb in English corresponds to an attribute of a relationship type in an ER diagram:

adverb attribute of relationship type

E.g. A London supplier sells a part with part name lamp for $50.

supplier sells part

location price pname

“London” “$50” “lamp”

London and Lamp are adjectives (and attribute values) of supplier and part resp, and $50 is an adverb which is an attribute of the relationship type sells.

ER Model

333333

Guideline 5: A gerund in English corresponds to a high level entity type (or aggregation) converted from a relationship type in an ER diagram:

gerund aggregation (or high level entity type)

Note: A gerund is a noun in the form of the present participle of a verb. For example 'shopping' in the sentence 'I like shopping‘.

E.g. Products are shipped to customers, and the shipping is performed by delivery men.

Ship to customerproduct

Delivery man

Performed by

ER Model

343434

Note: A clause is a group of words that contains a subject and a verb, but it is usually only part of a sentence.

Guideline 6: A clause in English is a high level entity type abstracted from a group of interconnected low level entity and/or relationship types in an ER diagram:

clause aggregation (or high level entity type)

E.g. Managers decide which machine is assigned to which employee.

manager decide machine employee Assigned

to

assignment

(One representation, not so good)

Q: Which representation is better?

machine employee Assigned

to

manager

(Another representation, better one)

decide

ER Model

353535

ER Construct notation Comparison

for participation constraint [Ever85, Knowledgeware]

ER Model Construct using the Chen approach for cardinality

ER Model construct using the "crow's foot"- notation

ER Model Construct

used in Teorey's book for cardinality [Rein85]

N N supply

partsupplier

Paperpublish 1 N

Editor Paper

publish

conference Paper

publish

Publisher JournalPublish 1 N

Publisher Journal Publish

Publisher Journal

Publish Max = many

Review Paperfor 1 1

Review Paper

Max = 1 Min = 0

Max = 1 Min = 1

forReview Paper

for

ER Model

Notation: O

means optional participation.

conference

supplier supplierpart partsupply supply

363636

ER Construct Notation Comparison (cont.)

Prev-Name

Intersection Entity

Prev-Name

Weak Entity or

Intersection Enity

Prev-Name

Weak Entity

Reviewer

Is-group-leader-of

Recursive entity

Reviewer

Is-group-leader-of

Recursive relationship

Reviewer

Is-group-leader-of

1 m

Recursive relationship

? Can't represnt

n-ary relationships

N-ary relationship

Institution

Written-at

Paper Author

Institution

Written-at

1

Paper Author

m m

ER Model

for participation constraint [Ever85, Knowledgeware]

ER Model Construct using the Chen approach for cardinality

ER Model construct using the "crow's foot"- notation

ER Model Construct

used in Teorey's book for cardinality [Rein85]

373737

ER Construct Notation Comparison (cont.)

No attributes are

allowed for

relationships

editor-id identifier (key) Name

editor-name descriptor (nonkey)

Name

specialty-areas

multivalued descriptor

m:1 Attribute

Name

Name

No attributes for relationships

Q: What are the strong and weak points of each notation? ER Model

for participation constraint [Ever85, Knowledgeware]

ER Model Construct using the Chen approach for cardinality

ER Model construct using the "crow's foot"- notation

ER Model Construct

used in Teorey's book for cardinality [Rein85]

38

Some other ERD notations

Multivalued attribute

ID dependency relationship

RX Y

Total participation, i.e. min occur is 1

circle area

Dotted oval and line indicate derived attribute

3939

Animal

d

Lion Horse Dog

Disjoint – every member of the super-class can belong to at most one of the subclasses. For example, an Animal cannot be a lion and a horse, it must be either a lion, a horse, or a dog.

Book

U

Text Novel Poetry

Union – every member of the super-class can belong to more than one of the subclasses. For example, a book can be a text book, but also a poetry book at the same time.

ER Model

4040

Example ERD notation.

Underlined attributes are identifiers (key attributes) of entity types.

ER Model

4141

Example ERD notation. Notations for disjoint and overlap subclasses.

4242

Another ERD notation. Arrow of a relationship type show the functional dependency. E.g. Course  Grad in TA relationship type;

Email  Student in Of relationship type.

ER Model

43

Steps of database design using ER Approach

Step 1. Understand the problem domain. Analyze database requirements. – Write a summary specification if not created yet. – What do we need to store into the database? – What queries and reports do we need to generate? – What are important people, places, physical things,

organizations, events and abstract concepts in the organization?

Step 2. Design a conceptual database schema by creating an ER diagram. Detail will be discussed.

ER Model

44

Step 3. Design a logical database schema. - Convert the ERD to a normal form ERD. - Translate the ERD into a relational schema.

Note: Another approach. First translate the ERD to a relational database schema, then normalize the relations in the schema to at least 3NF.

Step 4. Design a Physical database schema. - Denormalization. May need to de-normalize some normal form

relations for better performance. * adding redundant attributes in some relations * adding derived attributes in some relations * merging/splitting relations.

- choosing primary keys and foreign keys - defining indexes - Do database prototyping & modify the design if necessary. - Summarize the design assertion (integrity, security).

Detail will be discussed in the Physical Database Design chapter.

Step 5. Verify the design with users. Iterate the steps if necessary. ER Model

454545

Design a conceptual schema by creating an ER diagram Step 1. Identify the entity types. Step 2. Identify the relationship types and their participating entity

types. Step 3. Identify the attributes, keys, and identifier of each entity

type and relationship type and obtain an ER diagram Step 4. Convert the ER diagram to a normal form ER diagram. Step 5. Translate the NF-ER diagram to a relational database

schema (or other data models) Question: Is the resulting relational schema in normal form?

Advantages:

DBMS independent

Concentrate on “information requirements” not on “storage or access efficiency”, i.e. conceptual design.

Easy to understand by users and database designers

ER Model

46

Some decision rules/guidelines Rule 1:

Every entity type should be important in its own right within the problem domain.

Rule 2: IF an entity type (noun) has only one property to store and

relates to only one other entity type THEN it is an attribute of another entity type ELSE it is an entity type.

Rule 3: IF an entity type has only one data instance THEN do not model as an entity type.

Rule 4: IF a relationship type needs to have a unique identifier THEN model it as an entity type.

The first three rules are used to evaluate entity/object types or nouns, and the fourth rule is used to evaluate relationship types or verbs.

ER Model

474747

Example 1. (from C J Date’s book Question 14.2) A database used in an order-entry system is to contain information about customers, items, and orders. The following information is to be included.

- For each customer: Customer number (unique) Valid “ship to” addresses (several per customer) Balance Credit limit Discount

- For each order: Heading information: customer number, “ship-to” address, date of order. Detail lines (several per order), each giving item number, quantity ordered

- For each item: Item number (unique) Warehouses Quantity on hand at each warehouse Item description

For internal processing reasons, a “quantity outstanding” value is associated with each detail line of each order. [This value is initially set equal to the quantity of the item ordered and is progressively reduced to zero as partial shipments are made.] Design a database for this data. As in the previous question, make any semantic assumptions that seem necessary. ER Model

484848

Example 1. (cont.) An Order-Entry System (Question 14.2 in CJ. Date’s book)

Customer

ItemOrder

Warehouse

EX

1

m

m m

m

m

- First, only decide entity types and relationship types.

ER Model

494949

Example 1. (cont.) An Order-Entry System - then add attributes of entity types and relationship types.

Constraints: Between Address & Ship-to-Address

Customer

ItemOrder

Warehouse

EX

C# Address Balance

Credit Limit

Discount

Item# Description

QOH

SDL

Address

P#

QTY Order#

Ship-to- Address

Date

1

m

m m

m

m

QTY Outstanding

SDL – Stock Dangerous Level

ER Model

505050

Example 2. Recall the supplier-part-project database - SPJ

Supplier

Part Project

SPJ

m

mm Qty

Weight

ColorPnameP# J# Jname

S#

Sname Status

City

ER Model

515151

Example 3. (From C J. Date’s book Question 14.1) For each department the database contains a department number (unique), a budget value, and the department manager’s employee number (unique). For each department the database also contains information about all employees working in the department, all projects assigned to the department, and all offices occupied by the department. The employee information consists of employee number (unique), the number of the project on which he or she is working, and his or her office number and phone number; the project information consists of project number (unique) and a budget value; and the office information consists of an office number (unique) and the area of the office in square feet. Also, for each employee the database contains the title of each job the employee has held, together with date and salary for distinct salary received in that job; and for e a c h o f f i c e i t c o n t a i n s t h e n u m b e r s ( u n i q u e ) o f a l l p h o n e s i n t h a t o f f i c e .

Convert this hierarchical structure to an appropriate collection of normalized relations. Make a n y a s s u m p t i o n s y o u d e e m r e a s o n a b l e a b o u t t h e d e p e n d e n c i e s i n v o l v e d .

Department

Employee Project Office

Job

Salary history

Phone

ER Model

525252

Example 3. (cont.) (Question 14.1)

There are cycles in the ERD, each cycle may represent a constraint. E.g. R3 

R1 * R2 [Employee, Phone] R1 = R3 * R2 [Employee, Office] R4 = R7 * R5 [Employee, Department] R4 = R1 * R6 [Employee, Department]

Q: What are the meanings of the above constraints? Q: How to know whether these are really constraints or not?

Automatically or manually?

Department

Employee Project Office

Job Phone Salary history

R4 R5 R6

R7

R1ID

R3

R2

Date

Date Pay Title Desc

1 1

1

m m

m

m

m

m mm

1

m

1 1

1

m

1

535353

Example 4. Recall the relation CTX (Course, Teacher, Text) which has a Multivalued dependency (MVD):

Course Teacher | Text

Course

Teacher Text

CTX m

m

m Note: CTX has a MVD

Course

Teacher Text

CTX

m

m

m

CXCT

mm

m m CTX = CT CX

Note: CTX can be derived:

Should be:

ER Model

54

Draw a normal form ER diagram for a university library information system which stores information about books, journals, publishers, students, staff, borrowing of books, and reservation of books. Note that the library may have more than one copy for some of the books.

Example 5. Library Information System.

54

55

Example 5. (solution)

55

56

Example 6. Online Auction

Consider an ONLINE AUCTION database system in which members (buyers and sellers) participate in the sale of items. The data requirements for this system are summarized as follows:

• The online site has members, each of whom is identified by a unique member number and is described by an e-mail address, name, password, home address, and phone number.

• A member may be a buyer or a seller. A buyer has a shipping address recorded in the database. A seller has a bank account number and routing number recorded in the database.

• Items are placed by a seller for sale and are identified by a unique item number assigned by the system. Items are also described by an item title, a description, starting bid price, bidding increment, the start date of the auction, and the end date of the auction.

• Items are also categorized based on a fixed classification hierarchy.

ER Model

57

• Buyers make bids for items they are interested in. Bid price and time of bid is recorded. The bidder at the end of the auction with the highest bid price is declared the winner and a transaction between buyer and seller may then proceed.

• The buyer and seller may record feedback regarding their completed transactions. Feedback contains a rating of the other party participating in the transaction (1-10) and a comment.

Design an Entity-Relationship diagram for the ONLINE AUCTION database. (Do it yourself).

Example 6. Online Auction (cont.)

ER Model

585858

Translation of a (normal form) ER diagram to a relational database

Step 1. Assign role names to certain arcs in a cycle in the ER diagram (in order to conform to the universal relation assumption).

Note. Here, a cycle in an ER diagram is defined as a cycle in the corresponding graph of the ER diagram in which all entity types and relationship types are nodes in the graph and arcs which connect entity types and relationship types are edges in the graph, except for cycles formed only by ISA, UNION, INTERSECT, and DECOMPOSE special relationships.

Note: We can instead use the relaxed universal relation assumption which only requires the identifiers of entity types be unique.

ER Model

595959

Step 2. Assign identifiers for entity types involved in special relationships such as: ISA, UNION, INTERSECT, DECOMPOSE, and so far with no identifiers yet.

Step 3. Generate relations for each entity type. (1) All the m:1 and 1:1 attributes of an entity type E form a

relation. The keys and identifier of E are the keys and primary key of the generated relation.

(2) Each m:m attribute and the identifier of E form an all key relation.

(3) Each 1:m attribute and the identifier of E form a relation with the 1:m attribute as its key.

Note. All composite attributes are replaced by their components in the generated relations.

Q: How about weak entity type?

ER Model

606060

Step 4. Generate relations for each regular relationship type R. (1) All the identifiers (or role names) of the entity types participating

in R and all m:1 and 1:1 attributes of R form a relation. Keys and 1:1 attributes of R are keys of the generated relation, and the identifier of R is the primary key of the generated relation.

Further more, if A 

B is a full FD in the generated relation and A is not a key of R, then we record A 

B as a constraint

of the relation generated. (2) Each m:m attribute of R and the identifier of R form an all key

relation (i.e. all attributes of the relation form the only key of the relation). (3) Each 1:m attribute of R and the identifier of R form a relation

with the 1:m attribute as the key of the relation.

Q: How about special relationships such as ISA, EX, ID, etc., and aggregations?

ER Model

616161

- The role names AX, AY, BX, BY are assigned by step 1. - Note that the relationship type R3 has two FDs:

E#, D#  A# A# 

D#

{E#, D#} and {A#, E#} are keys of R3, and we designate {E#, D#} as the identifier of R3 .

E

A B

R1

R2

R3

D

ISA

C

E# E1 E2 E3

A2A# A1 A3

S2

B# B1 B2

S3

C1C# D1 D2 D#

S1

m/- m/1

1/m AX

AY

BX

BY

D12

Example 7.

Q: How to know there is another key (i.e. {A#, E#}) and how to find it?

626262

Relations generated are: (1) For entity type A

AE1(A#, A1, A2) AE3(A3, A#)

(2) For entity type B BE1(B#, B1) BE2(B#, B2)

(3) For entity type C CE1(C#, C1) (C# is generated) Constraint: C# ISA B# of BE1

i.e. CE1[C#] 

BE1[B#]

(4) For entity type D DE1(D#, D1, D2) (D12 is replaced by D1 and D2)

(5) For entity type E EE1(E#, E1, E2, E3) E# is primary key.

(6) For relationship type R1 R1R1(AX, BX) (AX, BX are generated) Constraints: AX ISA A#, BX ISA B#.

636363

(7) For relationship type R2 R2R1(AY, BY, S2) (AY, BY are generated) R2R2(AY, BY, S3) Constraints: AY ISA A#, BY ISA B#

(8) For relationship type R3

{D#, E#} is the primary key and {A#, E#} is another key Constraint: A#  D#

R3R1( A#, D#, E#, S1)

Note that (1) R3R1 is in 3NF but not in BCNF.

(2) No relation is generated for ISA relationship, it is translated to: C# ISA B#.

Questions: (1) Are all relations generated for each of the entity types in

3NF? BCNF? 4NF? (2) Are all the relations generated for each of the relationship

types in 3NF? BCNF? 4NF?

ER Model

646464

Entity Relations: Employee (E#, Name, Salary) Employee_Hobby (E#, Hobby) Employee_Skill (E#, Skill) Project (P#, Pname, Budget)

Relationship relation:

Emp_Proj(E#, P#, Progress)

Example 8.

EMPLOYEE EMP_ PROJ PROJECT

E# Name Salary

SkillHobby

P# Pname Budget

m m

Progress

 

ER Model

65

Customer

ItemOrder

Warehouse

EX

C# Address Balance

Credit Limit

Discount

Item# Description

QOH

SDL

Address

P#

QTY Order#

Ship-to- Address

Date

1

m m m

m

m

QTY Outstanding

Recall Example 1 - An Order-Entry System. Q: What are the relations translated from the entity types and the relationship types of the ER diagram?

666666

A Normal Form for Entity Relationship Diagrams Ref: Tok Wang Ling (4th ER conference, 1985)

Objectives for defining a normal form for ERDs. 1. to capture and preserve all the semantics of the real world of a

database which can be expressed in term of functional, multivalued, and join dependencies, by representing them explicitly in the ERD,

2. to ensure that all the relationship types represented in the ERD are non-redundant,

3. to ensure that all the relations translated from the ERD are in good normal form: either in 3NF or 5NF.

A normal form ERD may consist of 

composite attributes 

multivalued attributes 

weak entity types 

special relationships such as: existence dependent (EX), identifier dependent (ID), ISA, UNION, INTERSECT, DECOMPOSE relationships.

676767

Outline

1. Define the set of basic dependencies of an entity type

2. Define the entity normal form (E-NF)

3. Define the set of basic dependencies of a relationship type

4. Define the relationship normal form (R-NF)

5. Define the set of basic dependencies of an ERD

6. Define the normal form ERD (ER-NF)

7. Convert an ERD to a normal form ERD

ER Model

686868

Defn 1 The set of basic dependencies of an entity type E with identifier K, denoted by BD(E), is defined as:

(1) For each m : 1 attribute A of E K  A 

BD(E)

(2) For each 1 : m multivalued attribute A of E A  K 

BD(E)

(3) For each 1 : m and m : m multivalued attribute A of E K A 

BD(E)

(4) For each key K1 of E, K1 

K K  K1 

BD(E)

K1  K 

BD(E) (5) No other FDs or MVDs are in BD(E).

Defn 2 An entity type E is in entity normal form (E-NF) if and only if all given FDs and MVDs which only involve attributes of E, can be derived from BD(E).

ER Model

696969

Employee E#

Name

Skill

DegreeSexSSN

E.g. 1. (E# is the identifier)

BD(Employee) = { E#  SSN, Name, Sex SSN  E# E# Skill E# Degree }

Employee is in E-NF.

ER Model

707070

E.g. 2. (Address is a m : 1 composite attribute)

BD(Supplier) = { S#  Sname, S#  {City, Street, Zip}}

• Two well-known FDs are not in BD(Supplier), i.e., City, Street  Zip 

BD(Supplier)+ ,

Zip  City 

BD(Supplier)+

• Supplier is not in E-NF

Supplier

S#

City

Street

Zip

Address

Sname

ER Model

717171

Defn 3 Let R be a relationship type with identifier K, and F

be the associated set of FDs which only involve the identifiers of the set of entity types participating in R. The set of basic dependencies of R, BD(R) is defined as:

(1) For each 1 : 1 attribute A of R K  A 

BD(R)

A  K 

BD(R) (2) For each m : 1 single valued attribute A of R

K  A 

BD(R) (3) For each 1 : m multivalued attribute A of R

A  K 

BD(R) (4) For each 1 : m or m : m multivalued attribute A of R

K A 

BD(R) (5) Let A  B be a full dependency in F

such that A is a set of

identifiers of some entity types participating in R, and B is the identifier of some entity type participating in R. If A is a key of R or B is part of key of R, then

A  B 

BD(R) (6) No other FDs or MVDs are in BD(R).

727272

Defn 4 A relationship type R of an ER diagram is said to be in relationship normal form (R-NF) iff all given FDs and MVDs which only involve attributes of R and identifiers of entity types participating in R are implied by BD(R).

E.g. 3

ABD is the identifier of R. BD(R) = {ABD  EG, G  ABD, ABD F, ABD  C} R is in R-NF. Note: Suppose we have C  D 

F, then C  D is also in BD(R) by definition of BD(R) and so R is still in R-NF.

A

C D

R

B

E

F G

m m

1 m

E.g. 4

So, R is not in R-NF.

BD(R) = {AB  CD} CD 

BD(R)+

A

C D

R

B m/- m/-

1/m 1/1

737373

Defn 5 The set of basic dependencies of an ERD D, denoted by BD(D), is defined as the union of the sets of basic dependencies of all the entity types of D and the sets of basic dependencies of all relationship types of D.

Defn 6 An ERD D is in normal form (ER-NF) if it satisfies the following conditions:

(1) All attribute names are of different semantics, and all identifiers of entity types are unique. (This is to conform to the Relaxed Universal Relation Assumption which only requires the identifiers of all entity types be unique. We don’t really need to conform to the Universal Relation Assumption)

(2) Every entity type in the ERD is in E-NF. (3) Every relationship type in the ERD is in R-NF. (4) All given relationships and dependencies are implied by BD(D). (5) No relationship type (including its attributes) can be derived from

other relationship types by using join and projection. E.g.

R R2R1

R = R1 R2 then R can be derived from R1 and R2, and we don’t need to store its contents physically. The ERD is not in ER-NF.

Note: If

747474

Informally speaking,

(1) Cond’n (1) is required in order to conform to the Relaxed Universal Relation Assumption.

(2) Cond’n (2) ensures that all relations generated for all entity types are in 5NF.

(3) Cond’n (3) ensures that all relations generated for all regular relationship types are either in 3NF or in 5NF and there is no relation in BCNF but not in 4NF or 5NF.

(4) Cond’n (4) ensures that ERD has captured all relationship types and dependencies of the given database.

(5) Cond’n (5) ensures that no relationship type (together with its attributes) can be derived from other relationship types using join and projection operation.

ER Model

757575

Theorem:

The relations generated for each of entity type of a NF-ER diagram are in 5NF.

The relations generated for each of the relationship type of a NF-ER diagram are either in 3NF or 5NF.

ER Model

767676

Convert an ERD to a normal form ERD Step 1: Ensure that all identifiers of entity types are unique and all

attributes are of different semantics (to conform to the Relaxed Universal Relation Assumption).

Step 2: Convert any non E-NF entity type to E-NF. (remove all undesirable FDs and/or MVDs by introducing new entity types and relationship types)

Step 3: Convert any non R-NF relationship type to R-NF. (remove all undesirable FDs, MVDs and/or JDs by introducing new entity types and relationship types or by splitting the relationship type into smaller ones)

Step 4: Remove relationship types which have no associated attributes and is equal to the join and/or projection of other relationship types (as they can be derived).

ER Model

777777

Details of Step 2

(1) Each single valued attribute A is fully dependent on each key of E which does not contain A.

(2) All components of any composite single valued attribute A are fully dependent on each key of E which does not contain A.

(3) There is no non-trivial FDs defined among components of any composite attribute of E.

(4) No multivalued attribute of E is multi-dependent on a part of a key of E.

(5) No component of a composite many-to-many attribute of E is multi-dependent on the identifier of E.

(6) No component of a composite many-to-one attribute determines the identifier of E.

(7) Condition 1 of Lemma 4.2 of the NF-ER paper.

ER Model

787878

Step 1 E.g. A and B are of the same semantics

E1 E2

A B R1 R2

A

m m

1 m

A

E1 E2

E.g. A and B are of the same semantics E1 E2 E1 E2

A B

R m1

B

Step 2 E.g. A  B in a composite attribute of E

(E not in E-NF) (E in E-NF)

E E A

E# A

R

E#

1m

A 

B C D

B

C

D

797979

E.g. A  B in E and A is part of a key of E

(E not in E-NF) (E in E-NF)

E E D

E# D

R

E#

m/11/m

D 

C A B

C A

A B

m/1

E.g. A  C and A is part of the identifier of E, E becomes a weak entity type and the identifier is still AB.

(E not in E-NF) (E in E-NF)

E E A

A

ID

B A 

D B C

D C

ER Model

808080

Step 3 E.g. AB  D

(R not in R-NF) (R1 and R in R-NF)

A B

R A B

C D G

m m

m 

A B

R A B

C G

m m

m

R1

D

m m

or 

(R1 and R in R-NF)

A B

C

G

D R

A BR1

(Use aggregation, better solution)

818181

E.g. C  D

(R not R-NF) (R

in R-NF)

A B

R

C D

m m A B

R'

C G

m

1 G

 m

C

D

E.g. AD  F in R

(R not in R-NF) (R1 and R

in R-NF)

A B

R

D F

m m A B

R'

C

m

m

G

 m

A

G

C m

A R1

D

F

D

1

m

m

ER Model

8282

Some Database Design Tools

Some free and commerce Database Modeling tools can be found at

http://www.databaseanswers.org/modelling_tools.htm

ER Model

83

Summary • How to choose the identifier for an entity type? • Are the concepts of identifier of entity type and

primary key of relation of the relational model the same? If not, what are the main differences between them?

• When and why do we need to define identifiers for relationship types?

• What are the differences between cardinality and participation constraint? Which one is better (more powerful)?

• What is the main difference between EX and ID dependency relationships?

• Notation for aggregation in ERD ER Model

84

• Represent more than one FD in a relationship type • Generalization vs. specialization • English Sentence Structure and ER Diagram • In general when should a concept/thing be designed as

an attribute or as an entity type? E.g. phone? • Translation of a (normal form) ER diagram to a

relational database • Universal relation assumption and relaxed universal

relation assumption • What are the advantages of using ER Approach for

database design as compared to Decomposition and Synthesizing methods?

ER Model

  • Database Schema Design �
  • Topics
  • Slide Number 3
  • Slide Number 4
  • List of common entity types:
  • Slide Number 6
  • Slide Number 7
  • Slide Number 8
  • Slide Number 9
  • Different cardinalities of binary relationship types
  • Slide Number 11
  • Slide Number 12
  • Slide Number 13
  • Slide Number 14
  • Slide Number 15
  • Slide Number 16
  • Slide Number 17
  • Slide Number 18
  • Slide Number 19
  • Another example of Identifier-dependency relationship type
  • Slide Number 21
  • Slide Number 22
  • Slide Number 23
  • Slide Number 24
  • Slide Number 25
  • Slide Number 26
  • Slide Number 27
  • Slide Number 28
  • Slide Number 29
  • English Sentence Structure and ER Diagram� (self study)�
  • Slide Number 31
  • Slide Number 32
  • Slide Number 33
  • Slide Number 34
  • Slide Number 35
  • Slide Number 36
  • Slide Number 37
  • Some other ERD notations
  • Slide Number 39
  • Slide Number 40
  • Slide Number 41
  • Slide Number 42
  • Steps of database design using ER Approach
  • Slide Number 44
  • Slide Number 45
  • Some decision rules/guidelines
  • Slide Number 47
  • Slide Number 48
  • Slide Number 49
  • Slide Number 50
  • Slide Number 51
  • Slide Number 52
  • Slide Number 53
  • Example 5. Library Information System.
  • Example 5. (solution)
  • Slide Number 56
  • Slide Number 57
  • Slide Number 58
  • Slide Number 59
  • Slide Number 60
  • Slide Number 61
  • Slide Number 62
  • Slide Number 63
  • Slide Number 64
  • Slide Number 65
  • Slide Number 66
  • Slide Number 67
  • Slide Number 68
  • Slide Number 69
  • Slide Number 70
  • Slide Number 71
  • Slide Number 72
  • Slide Number 73
  • Slide Number 74
  • Slide Number 75
  • Slide Number 76
  • Slide Number 77
  • Slide Number 78
  • Slide Number 79
  • Slide Number 80
  • Slide Number 81
  • Some Database Design Tools
  • Summary
  • Slide Number 84