entity-relationship model ch. 3 mr john ortiz. lecture 2entity-relationship model2 overview of...

20
Entity-Relationship Model Ch. 3 Mr John Ortiz

Upload: john-bell

Post on 29-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Entity-Relationship ModelCh. 3

Mr John Ortiz

Lecture 2 Entity-Relationship Model 2

Overview of Database Design

Steps in building a database for an application

Requirement analysis. Specify what need to be modeled in a real-world domain

Conceptual design. Specify a high level schema using a database design model

Logical design. Refine a conceptual design to a schema using the data model of a DBMS

Physical design. Define the schema using the DDL of the DBMS

Database creation. Load data into a database

Lecture 2 Entity-Relationship Model 4

Requirement Analysis Need to interact with domain experts Application specific Time consuming Very important Difficult to be thorough

Lecture 2 Entity-Relationship Model 5

A Sample RequirementConsider a regional hospital. There are doctors, patients, nurses,

prescriptions, tests, … Each doctor has Id, Name, Specialty, Age,

Sex, … Patients see doctors, doctors prescribe

drugs to patients, … Each patient has one primary care

physician, a nurse is assigned to at most 5 patients, …

Lecture 2 Entity-Relationship Model 6

Conceptual Design Design a high level schema based on

requirements Why do we do a conceptual design?

To communicate with domain experts (use concepts of the application domain).

It is easier to set up a good model (focus on data content not structure)

Flexible (system independent, hmm… ) How to describe a conceptual design?

Use an ER Diagram (most popular)

Lecture 2 Entity-Relationship Model 7

Entity-Relationship Model Proposed by Peter Chen in 1976 Historically very popular Graphical Major concepts: entity type, relationship

type, attribute, constraints, …

Lecture 2 Entity-Relationship Model 8

Entity Type Entity. A real-world object distinguishable

from other objects. Each entity is described by a set of attributes (or properties).

Entity Type. A definition of a collection of entities with identical set of attributes.

Students

ssnname

gpa

Can informally think of entities as records

Lecture 2 Entity-Relationship Model 9

Relationship Type Relationship. An association between two or

more entities (usually of different types). A relationship may also have attributes.

Relationship Type. A definition of a collection of relationships with the identical set of attributes.

gpa

title

creditcno

gradename

Enrolled CoursesStudents

ssn

Not every entity participates in a relationship

Lecture 2 Entity-Relationship Model 10

Attributes Domain of an attribute. The set of values

the attribute may take. Many types of attributes. (simple vs

composite, single-value vs multi-value, stored vs derived)

Students

ssn gpaname

fname minit lname

hobby

bdate

age

Lecture 2 Entity-Relationship Model 11

Degree of Relationships Degree. Number of entity types involved

in a relationship type. (unary, binary, ternary, … )

Role. Part played by entities of a unary relationship.

namecityS#

name

Suppliers

P# color

Parts Order

ProjectsJ# dept

qty

Reports_To

lot

name

subor-dinate

super-visor

ssn

Employees

Lecture 2 Entity-Relationship Model 12

Key Constraint Key Attribute(s). A set of attributes of an

entity type whose values are unique for each entity of that type.

Key Constraint. Every (almost!) entity type must have a key attribute(s). (e.g., ssn of Students)

Lecture 2 Entity-Relationship Model 13

Participation Constraint Participation Constraint. Whether or not

every entity in an entity type participates in a type of relationship. Either total or partial.

Every course is taken by some students

gpa

gradename

takesStudents

ssntitle

creditcno

Courses

Lecture 2 Entity-Relationship Model 14

Cardinality Constraints Cardinality Ratio. Whether or not an entity

of a type may involve in a type of relationship with multiple entities of another type.

One-to-one (1-to-1). Each entity in E1 is associated with 0 or one entity in E2, and vice versa.

Employees manages Departments

ssn dnoname

agesince name

room

1 1

Other notation exists

Lecture 2 Entity-Relationship Model 15

Cardinality Constraints One-to-many (1-to-m). Each entity in E1 is

associated with 0 or more entities in E2, and each entity in E2 is associated with 0 or one entity in E1. The reverse is many-to-one (m-to-1).

Professors advises Students

ssn ssnname

roomname

gpa

1 m

To determine for Student, fix a Professor, see how many students are advised by him.

Lecture 2 Entity-Relationship Model 16

Cardinality Constraints Many-to-many (m-to-n). Each entity in E1

is associated with 0 or more entities in E2, and vice versa.

This is the default if not labeled

Students takes Courses

ssn cnoname

gpstitle

credit

m n

grade

Lecture 2 Entity-Relationship Model 17

Multiway Relationships What does it say?

What if r = 1?What if both r =1 and n=1?

Parts Suppliers

Projects

orderm n

r Pick an entity fromeach of the other 2entity types, how many entities in the third entity type are associated with the pair?

Lecture 2 Entity-Relationship Model 18

Weak Entity Type Weak Entity Type. An entity type without

its own key. Typically have a partial key. Must totally participate in an identifying relationship with a strong entity type. The relationship must be m-to-1 or 1-to-1.

How to refer to a weak entity?

Universities have Student_clubs

name cnamecity

sizephone

type

1 m

Lecture 2 Entity-Relationship Model 19

Extended ER Model (EER) Structural Constraint. The min & max

number of relationships in R that each entity in E must participate.

E(min, max)

R

Students takes Courses

ssn cnoname

gpstitle

credit

(1,5) (5,40)

grade

Lecture 2 Entity-Relationship Model 20

Cardinality ve Structural Cardinality Structural

The labels are placed in reverse order.

RE(0, 1) (0, 1)

F RE1 1

F

RE(0, m) (0, 1)

F RE1 m

F

RE(0, n) (0, m)

F REm n

F

RE(0, m) (1, 1)

F RE1 m

F

Lecture 2 Entity-Relationship Model 21

Look Ahead Next topic: Relational Data Model Read from the textbook:

Chapter 7.1-7.3