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

Slides:



Advertisements
Similar presentations
Entities and Relationships
Advertisements

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Data Modeling. What are you keeping track of? You begin to develop a database by deciding what you are going to keep track of. Each thing that you are.
Transform an ER Model into a Relational Database Schema
Relational Database Design Via ER Modelling
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 8.
Entity-Relationship Model and Diagrams (continued)
Methodology Logical Database Design for the Relational Model
Mapping ERM to relational database
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Assignements. CSC343: Intro. to Databases2 Exercise 1 Superkeys: Candidate keys: Primary key:
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 4 Mapping an ER model to tables © Akhilesh Bajaj,
Revision Instructor: Mohamed Eltabakh 1.
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations.
Announcements Midterm is Nov. 22 (8:15am – 9:45am) Covers until the end of Normalization You answer in the same exam paper Closed-Book, One sheet is allowed.
ER- Relational Mapping (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
Conversion from ER diagram to relational model 1 ER is a visual model The relational model is a matemathical model.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
COP Introduction to Database Structures
Databases (CS507) CHAPTER 7.
Data Modeling Using the ERD
Let try to identify the conectivity of these entity relationship
Assignements.
Chapter 5 Database Design
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Relational Database Design by ER- and EER-to- Relational Mapping
(Ref: ODMG2.0, R Cattell et al, Morgan Kaufmann, 1997)
CS 480: Database Systems Lecture 4 January 23, 2013.
RELATION.
Entity-Relationship Model
Exercise 1 Draw a UML class diagram that represents a travel agency's ticketing information. In this diagram, you should represent the concept of a person,
Tables and Their Characteristics
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Database Management Systems (CS 564)
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER- and EERR-to-Relational Mapping
Relational Database Design by ER-to-Relational Mapping
Constraints in Entity-Relationship Models
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
CSCI-100 Introduction to Computing
Payroll Management System
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
Translation of ER-diagram into Relational Schema
COS 346 Day 8.
How to translate ER Model to Relational Model
Entity-Relationship Model and Diagrams (continued)
Order Database – ER Diagram
The Entity-Relationship Model
Translation of ER-diagram into Relational Schema
Entity – Relationship Model
Session 2 Welcome: The seventh learning sequence
Instructor: Mohamed Eltabakh
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Relational Database Design by ER- and EER-to-Relational Mapping
Conceptual Data Modeling Using Entities & Relationships
Chengyu Sun California State University, Los Angeles
DBMS ER-Relational Mapping
Mapping an ERD to a Relational Database
Database Dr. Roueida Mohammed.
Entity Relation Model Tingting Zhang.
Database Management system
Database Management system
Chapter (7) ER-to-Relational Mapping, and other Relational Languages
Database Dr. Roueida Mohammed.
CS4222 Principles of Database System
Chapter 3 The Relational Model
Relational Database Design by ER-to-Relational Mapping
Presentation transcript:

CS 480: Database Systems Lecture 5 January 25, 2013

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.

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

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)

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)

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.

Dominated Entity Sets: Take-off()

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

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

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

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.

Relationship Sets: Reservation()

Relationship Sets: Reservation()

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

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

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.

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

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…

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.

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)

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.

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)

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)

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)

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.

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)

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)

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…

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)