Upload
alexander-roth
View
35
Download
0
Embed Size (px)
DESCRIPTION
Basic Schema Generation. Generate a schema for each entity set The attributes are the attributes of the entity set. The keys are the candidate keys of the entity set; choose a primary key. For each relationship set, adjust or add a schema. - PowerPoint PPT Presentation
Citation preview
ER_to_RDB: 1
Basic Schema Generation
• Generate a schema for each entity set– The attributes are the attributes of the entity set.– The keys are the candidate keys of the entity set; choose a primary key.
• For each relationship set, adjust or add a schema.– 1-1: merge schemas; add any relationship attributes; select a primary
key from among the primary keys of the merged schemas.– 1-m, m-1: to the schema on the many-side, add the primary-key
attribute(s) of the one-side; add any relationship attributes.– m-m: make a new schema from the primary-key attributes of the
connected entity sets and any relationship attributes; the key is the composite of the primary-key attributes if there are no key relationship attributes—otherwise semantically determine the key.
ER_to_RDB: 2
Schema Generation – Example
Room
NrDays
ArrivalDate
Guest
City
StreetNr
Name
GuestNrRoomNr
Name
NrBeds
Cost
hasreservation for
Room
NrDays
ArrivalDate
Guest
City
StreetNr
Name
GuestNrRoomNr
Name
NrBeds
Cost
hasreservation for
Generated schemas, with candidate keys underlined and primary keysdouble underlined: Room(RoomNr, Name, NrBeds, Cost) Guest(GuestNr, Name, StreetNr, City) Reservation(GuestNr, RoomNr, ArrivalDate, NrDays)
ER_to_RDB: 3
SQL DDLcreate table Room( RoomNr integer primary key, Name char(20) unique, NrBeds integer, Cost float );
create table Guest( GuestNr integer primary key, Name char(20), StreetNr char(20), City char(15), unique (Name, StreetNr, City) );
create table Reservation( GuestNr integer references Guest, RoomNr integer references Room, ArrivalDate char(6), NrDays integer, primary key (RoomNr, ArrivalDate) );
ER_to_RDB: 4
Sample Database Instance
r = Room(RoomNr Name NrBeds Cost) ------------------------------------------ 1 Kennedy 2 90 2 Nixon 2 80 3 Carter 2 80 4 Blue 1 60 5 Green 1 50
g = Guest(GuestNr Name StreetNr City) --------------------------------------------------- 101 Smith 12 Maple Boston 102 Carter 10 Main Hartford 103 Jones 6 Elm Hartford 104 Smith 4 Oak Providence 105 Green 10 Main Boston 106 Johnson 15 Main Boston
s = Reservation(GuestNr RoomNr ArrivalDate NrDays) ------------------------------------------------------ 101 1 10 May 2 101 2 20 May 1 101 3 15 May 2 102 3 10 May 5 103 1 12 May 3 104 4 10 May 2 104 4 17 May 2 104 4 24 May 2 105 1 15 May 7 106 2 11 May 2
ER_to_RDB: 5
Another Schema Generation Example(note the use of roles)
ER_to_RDB: 6
Basic Schema Generation for ISA
Room
RoomUnderConstruction
CompletionDate
NrDays
ArrivalDate
Guest
City
StreetNr
Name
GuestNrRoomNr
Name
NrBeds
Cost
hasreservation for
ISA
Room
RoomUnderConstruction
CompletionDate
NrDays
ArrivalDate
Guest
City
StreetNr
Name
GuestNrRoomNr
Name
NrBeds
Cost
hasreservation for
ISA
Based on meaning of ISA:
1.Collapse ISA and treat attributes as nullable attributes of the generalization: Room(RoomNr, Name, Cost, NrBeds, CompletionDate?)
2.Generate table for specialization with the key of its generalization: RoomUnderConstruction(RoomNr, CompletionDate)