Top Banner
Exercise 1 Back to the Book-Publisher Database 1
17
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Exercise 1 Back to the Book-Publisher Database 1.

Exercise 1

Back to the

Book-Publisher

Database

1

Page 2: Exercise 1 Back to the Book-Publisher Database 1.

Recall the Scenario

2

Page 3: Exercise 1 Back to the Book-Publisher Database 1.

Book-Publisher DB

3

What remains is the “Contracts” and their details

Page 4: Exercise 1 Back to the Book-Publisher Database 1.

Book-Publisher DB

4

• We modeled the contract between “Authors” & “Publishers”

• We made the contract “date” part of the key now an author can have multiple contracts with the same publisher over time.

What about contract lines ???

Page 5: Exercise 1 Back to the Book-Publisher Database 1.

Book-Publisher DB

5

This means a contract has only one line

Page 6: Exercise 1 Back to the Book-Publisher Database 1.

Book-Publisher DB

6

Not in the ER standards

Page 7: Exercise 1 Back to the Book-Publisher Database 1.

Book-Publisher DB

7

Page 8: Exercise 1 Back to the Book-Publisher Database 1.

Exercise 2

Design Hotel database

8

Page 9: Exercise 1 Back to the Book-Publisher Database 1.

Example: Hotel Database A Hotel has many branches

Hotel name, logo, address of HQ, Tel., manager, star rating Branch Id, address, Tel., Total capacity

Each branch has many rooms with different types and numbers. A room type defines Room size, Number of beds Has TV or not, Has Balcony or not These attributes of the room depend on its type

Guests can stay in a hotel for a period of time Guests have unique ID, name, address, Tel. We need to capture, the length of the stay, start date, end date, money paid

9

Page 10: Exercise 1 Back to the Book-Publisher Database 1.

10

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Room

Num

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 1

Observations:•Room type is modeled as attribute (causes redundancy) •Room number, is it numeric like 1001? If so, how come to be unique across branches?

Page 11: Exercise 1 Back to the Book-Publisher Database 1.

11

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Type

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 2

Observations:•Lets add relationships

RoomNum

Page 12: Exercise 1 Back to the Book-Publisher Database 1.

12

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Type

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 3

RoomNum

has

Of type

contains

Common mistake: Do not add “Branch ID” as an attribute to “Room” entity set. It is already captured by the weak relationship “contains”.

Observation: Not all relationships of “Room” are “supporting” relationships. Only the one that completes my key.

Page 13: Exercise 1 Back to the Book-Publisher Database 1.

Back to the Requirements A Hotel has many branches

Hotel name, logo, address of HQ, Tel., manager, star rating Branch Id, address, Tel., Total capacity

Each branch has many rooms with different types and numbers. A room type defines Room size, Number of beds Has TV or not, Has Balcony or not

Guests can stay in a hotel for a period of time Guests have unique ID, name, address, Tel. We need to capture, the length of the stay, start date, end date, money paid

13

Page 14: Exercise 1 Back to the Book-Publisher Database 1.

14

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Type

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 4

RoomNum

has

Of type

contains

Guest

IDAdd.

Tel.

Name

Money Paid

Length of stayStart date

End date

Observations:•“Stay” attributes should not be part of “Guest”

Page 15: Exercise 1 Back to the Book-Publisher Database 1.

15

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Type

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 5

RoomNum

has

Of type

contains

Guest

IDAdd.

Tel.

Name

Money Paid

Length of stayStart date

End dateStays inObservations:

•Still not quite right..•“Stays-in” 1-M or M-M??(Guest should be able to stay in diff. rooms)

Page 16: Exercise 1 Back to the Book-Publisher Database 1.

16

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Type

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 6

RoomNum

has

Of type

contains

Guest

IDAdd.

Tel.

Name

Money Paid

Length of stayStart date

End dateStays inObservations:

•Not done yet…•In this model, a guest cannot stay in the same room over diff visits!!!

Page 17: Exercise 1 Back to the Book-Publisher Database 1.

17

Hotel

NameHQ Add. Manager

RatingTel.

Branch

ID

Add.

Tel.

Capacity

Type

Type

Num Beds

Capacity

Has TV

Has Balcony

Ver. 7

RoomNum

has

Of type

contains

Guest

IDAdd.

Tel.

Name

Money Paid

Length of stayStart date

End dateStays inObservations:

•Start_date part of key•Length of stay derived attribute