Escolar Documentos
Profissional Documentos
Cultura Documentos
Functional Analysis
Access Specifications
Conceptual Design
Conceptual Model
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
Students
composite attribute
student_name
lastname
firstname
mid_initial
Fall 2001
Database Systems
Fall 2001
Database Systems
Mapping Entities
Students( sid, lastname, firstname, mid_initial )
hobbies
sid
Students
student_name
lastname
firstname
Fall 2001
Database Systems
buyid
cc_num email
Owners
Buyers
owner_name
phone
address
phone
lastname
firstname
mid_initial
street
state
city
zip
Fall 2001
Database Systems
Items
Bids
location
name
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.
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
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
Fall 2001
Database Systems
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
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
Buyers
amount
buy
(0,N)
Items
Stores
BUY
Item I1 I2 I3 I2
Fall 2001
Database Systems
Buyers
(0,N)
buy_item
Items
(0,N)
buy_from
(0,N)
sell_item
(0,N)
Stores
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