E-R Data Model

advertisement

CS4710 Introduction to Database Systems

E-R Data Model

Instructor:

Yi-Shin Chen

Office: EECS 3201

Email: yishin@cs.nthu.edu.tw

Office Hour: Tu. 1-2PM, Th. 3-4pm

Evolution of Data Management

Cons:

• The transaction errors cannot be detected on time

• The business did not know the current state

1950 : Univac had developed a magnetic tape

1951 : Univac I delivered to the

US Census Bureau

Con:

• Navigational programming interfaces are too-level

• Need to use very primitive and procedural database operations

Manual

Record

Managers

Punched-Card

Record Managers

Programmed Record

Managers

• Birth of high-level programming languages

• Batch processing

1900 1955

On-line Network

Databases

• Indexed sequential records

• Data independence

• Concurrent Access

1965 -1980

2007/3/01 CS4710 Introduction to Database

S stems

2

1

Evolution of Data Management

(Contd.)

E.F. Codd outlined the relational model

• Give Database users high-level set-oriented data access operations

Relational Databases && Client-

Server Computing

• Uniform representation

• 1985: first standardized of SQL

• Unexpected benefit

• Client-Server

•Because of SQL, ODBC

• Parallel processing

•Relational operators naturally support pipeline and partition parallelism

• Graphical User Interface

•Easy to render a relation

Multimedia Databases

• Richer data types

• OO databases

• Unifying procedures and data

• (Universal Server)

• Projects that push the limits

• NASA EOS/DIS projects • Oracle, Informix, Ingres

1970 1980 1995 2000

2007/3/01 CS4710 Introduction to Database

S stems

3

Data Models

ƒ Data model: a collection of concepts for describing data

ƒ Schema: a description of a particular collection of data, using the a given data model

ƒ Relational model of data: the most widely used model

}

}

Main concept → relation , basically a table with rows and columns.

Every relation has a schema → describes the columns, or fields

2007/3/01

World

Using a model

Schema that represents the World Car

Using ER Model drives

People

CS4710 Introduction to Database

S stems

4

2

E-R Model

ƒ Introduced by Peter Chen; ACM TODS, March 1976

} http://bit.csc.lsu.edu/~chen/

2007/3/01 CS4710 Introduction to Database

S stems

Additional Readings

ƒ Peter Chen. "English Sentence Structure and

Entity-Relationship Diagram." Information

Sciences, Vol. 1, No. 1, Elsevier, May 1983,

Pages 127-149

ƒ Peter Chen. "A Preliminary Framework for

Entity-Relationship Models." Entity-Relationship

Approach to Information Modeling and Analysis,

(edited by P. Chen), North-Holland (Elsevier),

1983, Pages 19 - 28

2007/3/01 CS4710 Introduction to Database

S stems

6

5

3

E-R Model Basics -Entity

ƒ

Based on a perception of a real world, which consists

}

A set of basic objects

Entities

}

Relationships among objects

ƒ Entity: Real-world object distinguishable from other objects

ƒ Entity Set: A collection of similar entities. E.g., all employees.

}

Presented as:

7 2007/3/01 CS4710 Introduction to Database

S stems

E-R Model Basics –Entity (Contd.)

ƒ An entity is described (in DB) using a set of attributes

}

All entities in an entity set have the same set of attributes

}

Attribute can be considered as a function that maps an entity into a domain

ƒ E.g.: S#: entity → integer

}

Presented as:

8 2007/3/01 CS4710 Introduction to Database

S stems

4

Attribute Types

ƒ Composite vs. Simple:

}

Useful when we sometimes need to refer to the entire attributes as a unit and sometimes to each of components

ƒ Multi-valued vs. Single Valued:

}

An attribute with a set of values for a same entity

2007/3/01 CS4710 Introduction to Database

S stems

9

Attribute Types (Cont.)

ƒ Derived vs. Stored:

}

Can be derived from either other attributes or related entities

ƒ Null attribute:

}

Not applicable for an attribute; or exist but missing; or not known

10 2007/3/01 CS4710 Introduction to Database

S stems

5

Example COMPANY Database

ƒ Requirements of the Company (oversimplified for illustrative purposes)

}

}

}

}

The company is organized into departments. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager.

Each department controls a number of projects . Each project has a name, number and is located at a single location.

We store each employee's social security number, address, salary, sex, and birthdates. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.

Each employee may have a number of dependents. For each dependent, we keep track of their name, sex, birthdates, and relationship to employee.

2007/3/01 CS4710 Introduction to Database

S stems

11

Identify the Entities

2007/3/01 CS4710 Introduction to Database

S stems

12

6

Identify the Attributes

2007/3/01 CS4710 Introduction to Database

S stems

13

E-R: Relationship Sets

ƒ Relationship: Association among two or more entities

ƒ Relationship Set: Collection of similar relationships.

}

Relationship set are presented as:

}

The relationship cannot exist without having corresponding entities

2007/3/01

ƒ 2-ary relationship set : Relates entity sets Student and Course

CS4710 Introduction to Database

S stems

14

7

E-R: Relationship Sets (Contd.)

ƒ Same entity set could participate in different relationship sets, or in different “roles” in same set

Student Enrolled Course

2007/3/01 CS4710 Introduction to Database

S stems

15

E-R: Role

ƒ Role: the function that an entity plays in a relationship is called its role

Student Enrolled Course

}

Normally implicit

ƒ Recursive relationship

}

Same entity set participates more than once in a relationship in different roles

}

Role name become essential

2007/3/01 CS4710 Introduction to Database

S stems

16

8

E-R: Relationship Sets (Contd.)

ƒ N-ary Relationship Set R :

}

}

Relates N entity sets E

1 entities e

1

E

1

, ..., e n

... E n

E n

; each relationship in R involves

Formal definition:

ƒ { ( e

1

, L , e

2

) e

1

E

1

, L , e n

E n

}

}

Example 3-ary relationship:

2007/3/01 CS4710 Introduction to Database

S stems

17

Mapping Cardinalities

ƒ # of entities to which another entity can be associated via a relationship set

}

Depends on the real-world modeled by the relationship set

ƒ Possible mapping cardinality of (binary) relation R between two entity sets A and B

}

One-to-one (1:1): Woman marrying men

Men

}

Many-to-one (N:1): Children Having mothers

Children

Mary

Have

Women

Mothers

}

One-to-many (1:N): Mothers having children

Mothers

Have Children

}

Many-to-many (M:N) : Students enrolled in courses

Student

Enrolled Course

2007/3/01 CS4710 Introduction to Database

S stems

18

9

The (min,max) Notation Relationship Constraints

Employee

Employee

2007/3/01

Manages

Works for

CS4710 Introduction to Database

S stems

Department

Department

19

Relationship

ƒ May have descriptive attributes

Student Enrolled Course

}

Must be uniquely identified by participating entities, without reference to descriptive attributes

ƒ Can students take the same course several times?

2007/3/01

Student Enrolled

CS4710 Introduction to Database

S stems

Course

20

10

S

1 z

S

2 z

S

3 z

S

4 z

S

5 z

S

6 z

Student

1

Enrolled r

1 r

2 r

3 r

4 r

5 r

6

1

Course z

C

1 z

C

2 z

C

3 z

C

4 z

C

5 z

C

6

2007/3/01 CS4710 Introduction to Database

S stems

21

S

1 z

S

2 z

S

3 z

S

4 z

S

5 z

S

6 z

S

7 z

2007/3/01

Student

N

Enrolled r

5 r

6 r

7 r

1 r

2 r

3 r

4

CS4710 Introduction to Database

S stems

1

Course z

C

1 z

C

2 z

C

3

22

11

S

1 z

S

2 z

S

3 z

S

4 z

2007/3/01

Student

N

Enrolled r

5 r

6 r

7 r

1 r

2 r

3 r

4

CS4710 Introduction to Database

S stems

M

Course z

C

1 z

C

2 z

C

3

23

Relationships

Student Enrolled Course

ƒ

Student will only take a specific course once

Student Enrolled Course

ƒ Student cam take the same course several times

2007/3/01 CS4710 Introduction to Database

S stems

24

12

Degree of relationship

ƒ Number of participating entity sets in a relationship

}

}

Binary relationships: involve two entities

Ternary/N-ary relationships: involves three/N entities

NTHU

Student

Enrolled Course

}

It’s always possible to replace a non-binary relationship set by a number of distinct binary relationships

Student Enrolled Course at NTHU

2007/3/01

ƒ But, depending on the actual real-world problem, one may be more appropriate than the other

CS4710 Introduction to Database

S stems

25

Parts

Think Think Think…..

Departments Parts Departments

Contracts

Suppliers

Supplies

Which one is more appropriate?

Needs

Deals

Suppliers

2007/3/01 CS4710 Introduction to Database

S stems

26

13

Example COMPANY Database

ƒ Requirements of the Company (oversimplified for illustrative purposes)

}

}

}

}

The company is organized into departments. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager.

Each department controls a number of projects . Each project has a name, number and is located at a single location.

We store each employee's social security number, address, salary, sex, and birthdates. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.

Each employee may have a number of dependents. For each dependent, we keep track of their name, sex, birthdates, and relationship to employee.

2007/3/01 CS4710 Introduction to Database

S stems

27

Identify the Relationships

2007/3/01 CS4710 Introduction to Database

S stems

28

14

2007/3/01

People e

1 z e

2 z e

3 z e

4 z e

5 z e

6 z e

7 z

Recursive Relationship

People Dependents of

CS4710 Introduction to Database

S stems z r

1 z r

2 z r

3 z r

4 z r

5 z r

6

Dependents of

29

Key

ƒ Entities and relationships are distinguishable using various keys

ƒ Types:

}

}

}

Superkey: a combination of one or more attributes that allow us to identify uniquely and entity in an entity set

ƒ

E.g.: Student-ID, Name & Student-ID

Candidate key: a minimal superkey that uniquely identifies an entity

ƒ

E.g.: Student-ID, name & address, phone#

Primary key: A candidate key chosen by DBA to identify entities of an entity

ƒ E.g.: Student-ID

2007/3/01 CS4710 Introduction to Database

S stems

30

15

Weak Entity vs. Strong Entity

ƒ Weak entity set

}

An entity set that does not have enough attributes to form a primary key

ƒ

Strong entity set

}

One with primary key

ƒ How to distinguish entities of a weak entity set?

}

}

Owner entity set and weak entity set must participate in a one-tomany relationship set (one owner, many weak entities)

Weak entity set must have total participation in this identifying relationship set

2007/3/01 CS4710 Introduction to Database

S stems

31

Weak Entity

ƒ An entity that does not have a key attribute

ƒ A weak entity must participate in an identifying relationship type with an owner or identifying entity type

ƒ Entities are identified by the combination of:

}

A partial key of the weak entity type

}

The particular entity they are related to in the identifying entity type

2007/3/01 CS4710 Introduction to Database

S stems

32

16

Example

ƒ Why the difference?

People Dependents of

Employee Dependents of Dependents

2007/3/01 CS4710 Introduction to Database

S stems

33

COMPANY ER Schema

2007/3/01 CS4710 Introduction to Database

S stems

34

17

High-Level Entity

ƒ High-level entity: Abstracted from a group of interconnected low-level entity and relationship types

Product Shipping Customer

Manager Decide

Machine Assigned to Employee

2007/3/01 CS4710 Introduction to Database

S stems

35

High-Level Entity (Contd.)

Customer Product Shipping

Manager Decide Machine

Assignment

Assigned to Employee

2007/3/01 CS4710 Introduction to Database

S stems

36

18

2007/3/01

Example

Student

Student

Semester

Enrolled

Enrolled

Semester

CS4710 Introduction to Database

S stems

Course

Course

37

Example: Reservation System

ƒ Reservation System for airline companies

}

}

Each company has many aircrafts

ƒ

Each has a registration number, make, model, and the maximum capacity of passengers

Each company has many flights

ƒ

Each flight departs from and arrives at registered airports

}

An airport also has an airport code, description name, city and country

}

Flight may stop at some intermediate stops

}

Customers could take a transfer flight from intermediate stops

ƒ Each flight has many seats

ƒ For every flight, the system should store a list of available seats

ƒ The seat arrangements are associated with aircrafts

ƒ Each seat can only be reserved to one customer

ƒ

Customers can make reservation without reserving seats

ƒ Each flight allow 20% overbooking

2007/3/01 CS4710 Introduction to Database

S stems

38

19

Example: Reservation System (Contd.)

ƒ The reservation system should keep

}

}

}

}

A unique identifier for each customer

ƒ

This identifier is assigned automatically once customers make a new reservation in the system

Customer information

Flight information

The time that reservation was made

}

A credit-card number associated with the reservation

}

A flag which indicates whether this particular reservation is paid or not

ƒ When a reservation is paid it is transformed automatically to a ticket

ƒ

The reservation can be canceled before flight departure, however the ticket is still valid (to exchange some products)

ƒ Each reservation might be associated with many flights

2007/3/01 CS4710 Introduction to Database

S stems

39

Example: Registration System

ƒ Registration System for Universities

}

Each school has many departments

}

Each department will offer many courses

ƒ Some courses are specially designed for students majoring in some subjects

ƒ Some courses will be offered regularly

ƒ For some courses, there will be many classes in one semester taught by different instructors

ƒ Some courses will have prerequisite subjects

ƒ Some classes will control the number of seats

ƒ The system should avoid time conflicts when students schedule their courses

}

For University System of Taiwan (UST)

2007/3/01 CS4710 Introduction to Database

S stems

40

20

Download