You are on page 1of 25

Database Design Process

Real World
Requirements Analysis
Functional
Requirements

Database
Requirements

Functional Analysis

E-R Modeling

Conceptual Design

Access
Specifications

Choice of a
DBMS

Conceptual
Model

Data Model
Mapping

Logical
Schema

Application Pgm Design

Fall 2001

Logical Design

Database Systems

Physical Design

Entity-Relationship Model
An entity is a collection of real-world objects that
have many common properties.
Examples: Students, Instructors, Courses, Sections
Student entities have properties: name,
address, major, graduation-year
A student may be John Smith, 22 Sage Rd.,
Computer Science, 2000
An attribute is a data item that describes a property
of an entity

Fall 2001

Database Systems

Entities
primary identifier
sid

multi valued attribute


hobbies

Students

composite attribute

student_name

lastname

Fall 2001

firstname

mid_initial

Database Systems

Mapping Entities to Relations


Each entity in an E-R model is mapped to a separate
relation
the primary identifier is mapped to the primary key
(underlined!)
all regular attributes are mapped to an attribute in the
table
each subpart of a composite attribute is mapped to a
different attribute
each multi-valued attributed is mapped to a separate
relation that inherits the primary key of the parent
relation

Fall 2001

Database Systems

Mapping Entities
Students( sid, lastname,
firstname, mid_initial )

sid

hobbies

Students

Foreign key sid references


the Students relation!

student_name

lastname

Fall 2001

firstname

Hobbies( sid, hobby )

mid_initial

Database Systems

Map the Auction Entities


buyer_name
oid

#itemsold
email

Owners
owner_name

lastname

firstname

phone

buyid

Database Systems

phone
city

street
state

Fall 2001

email

Buyers
address

mid_initial

cc_num

zip

Map the Auction Entities


iid

description

Items
name

bid

Bids
location

date/time
date

Fall 2001

Database Systems

amount
time

Relationships

Given a set of entities E1,E2,,Ek, a relationship R defines a


rule of correspondence between these entities.
An instance r(e1,e2,,ek) of the R relation means entities
e1,e2,,ek are in a relation r at this instance.
If two people are married, they are in a relationship:
married(Bob, Margaret)
If a student A takes a course C offered by professor B,
then A,B,C are in a relationship.

Fall 2001

Database Systems

Relationships
binary relationship
own

Items

Owners
accept

Buyers

place

Bids
date

ternary relationship
Fall 2001

Database Systems

Cardinalities of Relationships
Participation cardinalities of a relationship R for an
entity E are:
min-card(E, R) : the minimum number of entities
in E that should be mapped via R
max-card(E, R): the maximum number of
entities in E that can be mapped via R
Own is a relation between owner and item
Should each owner be selling items?
How many items can an owner sell?

Fall 2001

Database Systems

10

Cardinalities of Relationships
E

One-to-one relationship
min-card(E, R)=0
max-card(E,R)=1
min-card(F,R)=0
max-card(F,R)=1

Fall 2001

Many-to-one relationship
min-card(E, R)=0
max-card(E,R)=N
min-card(F,R)=1
max-card(F,R)=1

Database Systems

Many-to-many relationship
min-card(E, R)=0
max-card(E,R)=N
min-card(F,R)=0
max-card(F,R)=N

11

Cardinalities
own

(1,1)

Items

(0,N)

Owners

(0,N)

(0,N)
accept

Buyers

Bids

place
(0,N)

(1,1)

(0,1)
date

Fall 2001

Database Systems

12

Cardinalities

If max-card(E,R)=1 then E has single-valued participation in


R

If max-card(E,R)=N then E has multi-valued participation in


R

Given a binary relation R between E and F, R is said to be


one-to-one if both E and F have single-valued
participation
one-to-many if E has single and F has multi-valued
participation
many-to-many if both E and F have multi-valued
participation

Fall 2001

Database Systems

13

Mapping Relationships to Relations

Map one-to-one and one-to-many (or many-to-one)


relationships into the existing relations (derived from entities)
If E-R-F is one-to-many, then include the primary key of the
relation for F in the relation for E.
If E-R-F is one-to-one, then include key for E in F, or the
key for F in E.
If E-R-F is many-to-many, create a new relation for R that
has the primary keys for both E and F.
If R has attributes, migrate them to the relation with the
foreign keys!

Fall 2001

Contains Foreign Key(s)


Database Systems
14

Mapping the Auction Database


Owners( oid, itemsold, lastname, firstname,
phone )

mid_initial,

OwnerEmail( oid, email )


Buyers( buyid, buyername, ccnum,street, state, city,
zip, phone )
BuyerEmail( buyid, email )
Items( iid, name, location, description, oid )
Bids( bid, date, time, amount, acceptingoid,
acceptdate, buyid, iid )

Fall 2001

Database Systems

15

Cardinalities
own

(1,1)

Items

(0,N)

Owners

(0,N)

(0,N)
accept

Buyers

Bids

place
(0,N)

(1,1)

(0,1)
date

Fall 2001

Database Systems

16

Problem
Consider the design of a database to manage airline
reservations:
For flights, it contains the departure and arrival
airports, dates and times
For flights, it also contains a number of different
pricing plans with different conditions (Saturday
stay, advance booking, etc.)
For passengers, it contains the name, telephone
number and seat type preference
Reservations include the seat assigned to a
passenger
Passengers can have multiple reservations

Fall 2001

Database Systems

17

Solution
time

date

pricing plan

depart
airport

(0,N)
(0,N)

(1,1)
(1,1)

flight
name

arrive
date

(0,N) conditions

time
(0,N)

reservation

passenger
seat
name
phone
Fall 2001

seat pref
Database Systems

18

Entity Relationship Model


Foreign key
to Employees

Entities play different roles in a relationship


Supervised-by
(1, 1)

eid

Employees

Employees(eid, , supervisor-id)

supervises
Supervisor-of
(0, N)

Recursive
relationship

employee-supervisor
(1, 1)

Employees

supervises
supervised
(0, N)

Fall 2001

project-supervisor
(1, N)

Projects

Database Systems

19

Entity Relationship Model

Many-to-many relationships are translated into new


relations

Buyers

(0,N)

amount

(0,N)

buy

Items
(0,N)

Stores

Fall 2001

BUY

Item

Buyer Store Amount

I1

B1

S1

I2

B1

S2

I3

B4

S1

I2

B5

S2

Database Systems

20

Entity Relationship Model

Ternary relationships may be represented by binary


relationships
(0,N)

Buyers

(0,N)

buy_item

Items

(0,N)

(0,N)

sell_item

buy_from
(0,N)

Fall 2001

Stores

(0,N)

Is this conceptually
equivalent to the
previous ternary
relationship?

Database Systems

21

Weak Entities

The existence of a weak entity W depends on the existence


of another (strong) entity E through a relationship R.

(Alternate) Two different weak entities may have the same


identity (key) if they are related to two different strong
entities.

Bank

(0,N)

(1,1)

has

number

name

Fall 2001

Branch

Database Systems

address

22

Weak Entities
Weak entities can be mapped to the relational
model by:
Map each weak entity E that depends on a strong
entity F to a new relation R
Relation R contains all the attributes in E and the
primary key of F
The primary key for R is the primary key of E and the
primary key of F

Fall 2001

Database Systems

23

Generalization Hierarchies
Lower items inherit attributes of their parents
date

Concerts

location

Option 1. Translate into


a single relation with a
flag for the type of entity
[many null values]
Classical

Other

orchestra
pieces

soloists
conductor

Fall 2001

performers

Option 2. Translate into


three entities and two
is-a relationships, then
translate the resulting graph.

Database Systems

24

Extensions
All relational DBMSs come with extensions that give more
flexibility to the DBA
Examples from Informix
composite attributes -> translate as a record address of
type ROW(street string, city string, state string, zip
string)
multi-valued attributes -> translate into collection types
such as sets, lists, multi-sets (bags)
hierarchies -> create typed tables and translate into a
type hierarchy.
REMEMBER, the extensions complicate the data model
and make certain SQL queries much harder or impossible,
leaving the database programmer with a much harder job
of maintaining the database!
Fall 2001
Database Systems
25

You might also like