Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 480: Database Systems Lecture 5 January 25, 2013.

Similar presentations


Presentation on theme: "CS 480: Database Systems Lecture 5 January 25, 2013."— Presentation transcript:

1 CS 480: Database Systems Lecture 5 January 25, 2013

2

3 Recap Relational Model
Set-oriented Model Set of Attributes form a relation scheme Tuples is an assignment of values to each attribute Set of Tuples form a relation Set of relations form the relational database.

4 From ER-diagrams to Relational Model
For each (non-dominated, non-specialization) entity set E with attribute set {A1,A2,…,An} we will have a relation scheme E(A1,A2,…,An). The key of this relation E is the same key of the entity set E. Book calls non-dominated STRONG

5

6 Non-dominated Entity Sets:
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary)

7 Non-dominated Entity Sets:
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary)

8 Dominated (Weak) Entity Sets
Let A be a dominated entity set and let B be the dominating entity set. Let the key of B consist of {b1,b2,…,bn}. Also let A have attributes {a1,a2,…,am}. Then we will have a relation scheme A(a1,a2,…,am, b1,b2,…,bn). The key of relation A will consist of any key attributes of the entity set A and all of {b1,b2,…,bn}. Weak because it doesn’t necessarily have a key on its own.

9 Dominated Entity Sets:
Take-off()

10 Dominated Entity Sets:
Take-off(date) Will contain all attributes of Take-off.

11 Dominated Entity Sets:
Take-off(date, number) Will contain all key attributes of the dominating entity set.

12 Dominated Entity Sets:
Take-off(date, number) Keys will be all the keys of the dominating entity (Flight) and keys if any of the dominated entity (Take-off).

13 Relationship Sets Each relationship set R will become a relation scheme R. The keys of all the participating relationships will be part of the relation scheme R. Also, any attributes that the entity set R had will be part of the relation R.

14 Relationship Sets: Reservation()

15 Relationship Sets: Reservation()

16 Relationship Sets: Reservation(name, address, Take-off.date) All keys of participating relationships.

17 Relationship Sets: Reservation(name, address, Take-off.date) All keys of participating relationships. Are these all the keys of the participating entities?

18 Reservation(name, address, Take-off.date, Flight.number)
Relationship Sets: Reservation(name, address, Take-off.date, Flight.number) All keys of participating relationships. Look past the diagram Are these all the keys of the participating entities? It’s missing the Flight.number, which is part of the Take-off key.

19 Reservation(name, address, Take-off.date, Flight.number,
Relationship Sets: Reservation(name, address, Take-off.date, Flight.number, date, class, seat#) All attributes of the relationship itself. Look past the diagram

20 From Relationships to Relations
The keys for the relation R will depend on the cardinality constraints. Many-to-many – All keys of the participating entity sets will form part of the key of the relation R. One-to-one – Choose the key of either of the participating entity sets as the key for R. One-to-many – Choose the key of the many side. Ask why at least for the one-to-one… Also for the one-to-many…

21 Reservation(name, address, Take-off.date, Flight.number,
Relationship Sets: Reservation(name, address, Take-off.date, Flight.number, date, class, seat#) Take-off-OF-Flight( Take-off.date, Flight.number) Take-off-BY-Plane(plane-id, Plane-TYPE(plane-id, manufacturer, number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number) DISCUSS PILOT WHAT ABOUT N-ary RELATIONSHIPS? All many’s then all keys form part. Some one’s then the keys for all the many’s form part of the key.

22 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-OF-Flight(Take-off.date, Flight.number) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Plane-TYPE(plane-id, manufacturer, number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)

23 Weak Entity Sets Don’t have sufficient attributes to form a key.
Dominated Entity Sets (Take-off) and Specialized Entity Sets (Pilot) are examples. Redundancy will exist if we give a relation to the relationship and the weak entity set.

24 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, Flight.number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-OF-Flight(Take-off.date, Flight.number) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Plane-TYPE(plane-id, manufacturer, number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)

25 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-OF-Flight(Take-off.date, Flight.number) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Plane-TYPE(plane-id, manufacturer, number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)

26 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Plane-TYPE(plane-id, manufacturer, number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)

27 Combination of Schemas
An entity set E in a relationship R has full participation if every element of E participates in at least one relationship in R. For example: Plane(plane-id) Plane-Model(manufacturer, number, capacity) Plane-TYPE(plane-id, manufacturer, number) Every plane has a plane-model, then every plane participates in the TYPE relationship. Plane and Plane-Type can be combined into one relation Plane(plane-id,manufacturer,number) This can be done for many-to-one relationships. Combine the “many” relation and the relationship. Understand WHY it can be done.

28 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, Flight.number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Plane-TYPE(plane-id, manufacturer, number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)

29 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id,manufacturer,number) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, Flight.number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)

30 Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id,manufacturer,number) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, Flight.number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number) WHAT ARE THESE? Foreign Keys What are the implications of them and what’s important about them? Adds a constraint to the database. Referential Integrity… If a passenger changes his name then it should change also on the RESERVATION table…

31 Final Airline Relational Schema
Passenger(name, address, phone#,frequent-flyer#) Flight(number, source, destination, departure-time, arrival-time) Plane(plane-id,manufacturer,number) Plane-Model(manufacturer, number, capacity) Employee(ss#, name, address, salary) Take-off(date, Flight.number) Reservation(name, address,Take-off.date, Flight.number, date, class, seat#) Take-off-BY-Plane(plane-id, Take-off.date, Flight.number) Pilot(SS#, flight-hours) Can-fly(SS#, manufacturer, number)


Download ppt "CS 480: Database Systems Lecture 5 January 25, 2013."

Similar presentations


Ads by Google