Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 480: Database Systems Lecture 4 January 23, 2013.

Similar presentations


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

1 CS 480: Database Systems Lecture 4 January 23, 2013

2 Exercise ER-Diagram Database System for an Airline to be used for:
Booking Flights Managing Flights, Crew Members, and their Planes Construct an ER-diagram for this Airline Enterprise.

3 Exercise ER-Diagram #2 Construct an ER-Diagram for a Course Registration System.

4

5 THE RELATIONAL MODEL

6 Relational Model Proposed in 1970 by E.F. Codd
“A Relational Model of Data for Large Shared Data Banks”, Communications of the ACM 13(6) Simplicity compared to previous models no longer in use (network model or hierarchical model) ER-diagrams good for modeling and visualizing Relational model brings us closer to the data representation.

7 Relational Model Every node (sets) in ER-diagram gets a relation.
Weight Supplier Id Price Color SUPPLIER Don’t confuse relation with relationships. Relation is a new concept SUPPLIES PART Part Id Supp. Name City Part Name

8 Relational model Every node (sets) in ER-diagram gets a relation.
Supplier(supplier-id,supplier-name,city) Part(part-id,part-name,color,weight) Supplies(supplier-id,part-id,price) Recall: Why did I choose the attributes of SUPPLIES as such, and it’s key as well…

9 Relational Database Instance
Supplier: Part: Supplier-id Supplier-name City 123 ACME Chicago 234 BBQ Inc. New York 345 COLE London 456 Dave’s Part-id Part-name Color Weight 12 Nut Gray 15 Bolt Orange 17 5 Screw Blue Supplier-id Part-id Price 123 12 1 234 15 2 1.5 345 5 1.25 Supplies:

10 Attributes An attribute is a symbolic name
eg. Supplier-name, part-id, price With each attribute is associated a domain

11 Attributes An attribute is a symbolic name
eg. Supplier-name, part-id, price With each attribute is associated a domain What are domains for the following attributes? Social-Security # Birthdate Price Gender Age

12 Relation Scheme A relation scheme, R, is a set of attributes {A1,A2,…, An}and is denoted by: R(A1,A2,…,An) Ex: Supplier(supplier-id,supplier-name,city) Supplier(supplier-name,supplier-id,city) Both are the same. No duplicates and no order.

13 Tuples Def: A tuple on a relation scheme R is an assignment of values, one to each attribute of R. The value of attribute Ai is taken from its domain. Part-id Part-name Color Weight 12 Nut Gray 15 Bolt Orange 17 5 Screw Blue  tuple  tuple  tuple

14 Relation A relation on R, r(R), is a set of tuples on R.
Relations can be looked at as tables. Supplier-id Supplier-name City 123 ACME Chicago 234 BBQ Inc. New York 345 COLE London 456 Dave’s Part-id Part-name Color Weight 12 Nut Gray 15 Bolt Orange 17 5 Screw Blue

15 Relational Model Set of relation schemes forms the relational schema
eg. Supplier database Supplier(supplier-id,supplier-name,city) Part(part-id,part-name,color,weight) Supplies(supplier-id,part-id,price)

16 Relational Database Set of relations forms the relational database.
Part-id Part-name Color Weight 12 Nut Gray 15 Bolt Orange 17 5 Screw Blue Supplier-id Supplier-name City 123 ACME Chicago 234 BBQ Inc. New York 345 COLE London 456 Dave’s Supplier-id Part-id Price 123 12 1 234 15 2 1.5 345 5 1.25 Then that’s the relational model: Relational Scheme’s, each with a set of attributes They for relations that have tuples that are based on these schemes The database is a set of relations or tables.

17 Keys Same concept introduced for ER model applies in the relational model. Previous def: The key of an entity set E is a minimal subset of the attributes of E that uniquely indentifies an entity in the set.

18 Keys Same concept introduced for ER model applies in the relational model. Previous def: The key of an entity set E is a minimal subset of the attributes of E that uniquely indentifies an entity in the set. Def: The key of a relation R is a minimal subset of the attributes of R that uniquely indentifies a tuple of the relation. This subset of attributes adequately distinguishes between elements of the relation (tuples).

19 Keys in the Relational Model
Let K be the key of R. No relation instance of R is allowed to have two tuples that are equal on K. No proper subset of K satisfies condition 1.

20 Keys in the Relational Model
Let K be the key of R. No relation instance of R is allowed to have two tuples that are equal on K. No proper subset of K satisfies condition 1. Supplier-id Supplier-name City 123 ACME Chicago 234 BBQ Inc. New York 345 COLE London 456 Dave’s Is {city} a valid key?

21 Keys in the Relational Model
Let K be the key of R. No relation instance of R is allowed to have two tuples that are equal on K. No proper subset of K satisfies condition 1. Supplier-id Supplier-name City 123 ACME Chicago 234 BBQ Inc. New York 345 COLE London 456 Dave’s Is {supplier-id,city} a valid key?

22 Keys in the Relational Model
Let K be the key of R. No relation instance of R is allowed to have two tuples that are equal on K. No proper subset of K satisfies condition 1. Supplier-id Supplier-name City 123 ACME Chicago 234 BBQ Inc. New York 345 COLE London 456 Dave’s {supplier-id} is the key

23 Keys in the Relational Model
Let K be the key of R. No relation instance of R is allowed to have two tuples that are equal on K. No proper subset of K satisfies condition 1. Does every relation have a key?

24 Keys in the Relational Model
Let K be the key of R. No relation instance of R is allowed to have two tuples that are equal on K. No proper subset of K satisfies condition 1. Does every relation have a key? Relation is a set of tuples so yes. At worst, every attribute will form part of the key.

25 Data Manipulation Languages (DML)
Language for accessing and manipulating the data. Languages for expressing queries. Queries – requests for information from the database. Ex. Retrieve the supplier names for suppliers located in London. Retrieve the parts that are shipped by suppliers in Paris (involves 2 relations).


Download ppt "CS 480: Database Systems Lecture 4 January 23, 2013."

Similar presentations


Ads by Google