Você está na página 1de 25

Database Design Process

Real World Requirements Analysis


Functional Requirements Database Requirements

Functional Analysis
Access Specifications

E-R Modeling Choice of a DBMS

Conceptual Design
Conceptual Model

Data Model Mapping


Application Pgm Design

Logical Design
Logical Schema

Fall 2001

Database Systems

Physical Design 1

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

firstname

mid_initial

Fall 2001

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 )
hobbies

sid

Hobbies( sid, hobby )

Students

student_name

Foreign key sid references the Students relation!


mid_initial

lastname

firstname

Fall 2001

Database Systems

Map the Auction Entities


buyer_name oid #itemsold

buyid

cc_num email

Owners

email

Buyers

owner_name

phone

address

phone

lastname

firstname

mid_initial

street
state

city
zip

Fall 2001

Database Systems

Map the Auction Entities


iid
description bid

Items

Bids
location

name

date/time date time

amount

Fall 2001

Database Systems

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 9

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 R F E R F E R F

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
(1,1) own (0,N)

Items
(0,N)

Owners
(0,N) accept

Buyers
(0,N)

place (1,1)

Bids

(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

Database Systems

Contains Foreign Key(s) 14

Mapping the Auction Database


Owners( oid, itemsold, lastname, firstname, mid_initial, phone ) 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
(1,1) own (0,N)

Items
(0,N)

Owners
(0,N) accept

Buyers
(0,N)

place (1,1)

Bids

(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
date depart airport (0,N) (0,N) arrive (1,1) (1,1) time (0,N) flight name time pricing plan

date

(0,N) conditions
reservation

passenger
seat name
Fall 2001

phone

seat pref
Database Systems 18

Entity Relationship Model


Foreign key to Employees

Entities play different roles in a relationship


eid
Supervised-by (1, 1)

Employees(eid, , supervisor-id)

Employees

supervises
Supervisor-of (0, N) employee-supervisor (1, 1)

Recursive relationship
project-supervisor (1, N)

Employees
supervised (0, N)

supervises

Projects
Database Systems 19

Fall 2001

Entity Relationship Model


Many-to-many relationships are translated into new relations
(0,N) (0,N)

Buyers
amount

buy
(0,N)

Items

Stores

BUY

Item I1 I2 I3 I2

Buyer Store Amount B1 B1 B4 B5 S1 S2 S1 S2 3 4 5 2


20

Fall 2001

Database Systems

Entity Relationship Model


Ternary relationships may be represented by binary relationships
(0,N) (0,N)

Buyers
(0,N)

buy_item

Items
(0,N)

buy_from
(0,N)

sell_item
(0,N)

Stores

Is this conceptually equivalent to the previous ternary relationship?


21

Fall 2001

Database Systems

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.

(0,N)

(1,1)

Bank

has

Branch

name
Fall 2001 Database Systems

number

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
orchestra pieces soloists conductor
Fall 2001

Other
Option 2. Translate into three entities and two is-a relationships, then translate the resulting graph.
24

performers

Database Systems

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

Você também pode gostar