Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 The Relational Data Model By Yue Lu CS157B Spring 2008 Instructor: Dr.Lee.

Similar presentations


Presentation on theme: "Chapter 5 The Relational Data Model By Yue Lu CS157B Spring 2008 Instructor: Dr.Lee."— Presentation transcript:

1 Chapter 5 The Relational Data Model By Yue Lu CS157B Spring 2008 Instructor: Dr.Lee

2 Relational Model Concepts The Relational Model of Data is based on the concept of a Relation The Relational Model of Data is based on the concept of a Relation A Relation is a two-dimensional table A Relation is a two-dimensional table –The columns of the table represent attributes –The rows of the table represent entities

3 Relational Model Concepts A relation schema is the name and the list of attributes of a relation A relation schema is the name and the list of attributes of a relation –Grade (studentId, assignmentId, points, dateSubmitted) A tuple is a row of a table, one value for each attribute A tuple is a row of a table, one value for each attribute –(101, 102, 92, 2/28/08)

4 Model Concepts Domain D is a set of atomic values Domain D is a set of atomic values –Atomic means that each value is indivisible Attribute A is the name of a role played by some domain Attribute A is the name of a role played by some domain Relation schema R is the specification of a relation Relation schema R is the specification of a relation –Given by a name and list of attributes –Degree of a relation is the number of attributes Relation (instance) r(R) of a relation schema Relation (instance) r(R) of a relation schema –A set of n-tuples, n is degree of relation schema

5 Characteristics of Relational Model Relation is a set of tuples Relation is a set of tuples –No ordering of tuples –No duplicate tuples no two rows have all the same values no two rows have all the same values Each attribute value is atomic Each attribute value is atomic –So no multiple-valued or composite attributes –called first normal form Each relation is a set of assertions Each relation is a set of assertions –Each represents a fact –Some facts are about relationships

6 Representing E-R Model as Relations Entity class  Relation schema Entity class  Relation schema Entity  row of table Entity  row of table –set of all entities of class  table Attribute  column definition (attribute) Attribute  column definition (attribute) –attribute value  table element Relationship type  Relationship type  –relation schema –attribute(s) of relation schema

7 Example of Relation Schema and Table Figure 4.2 P75 Figure 4.2 P75 –Customer(accountID,lastName,firstName, street, city, state, zipcode, balance) account Id lastNa me firstNa me streetcitystat e zipcod e balan ce 101BlockJane1010 Main St. Apopk a FL304580.00 102Hamilt on Cherry3230 Dade St. Dade City FL305554.47 103Harriso n Kate103 Dodd Hall Apopk a FL3045730.57 104BreauxCarroll76 Main St. Apopk a FL3045834.58

8 Attributes are atomic Composite attributes – –simple attribute for each field – –Customer (accountId, lastName, firstName, street, city, state, zipcode) Multi-valued Attributes –Represent as Tables – –See Figure 4.3

9 Attributes are atomic (cont.) All other attributes values are duplicated except OtherUser All other attributes values are duplicated except OtherUser The key of the schema is the set {accountId, OtherUser} The key of the schema is the set {accountId, OtherUser} account ID lastNam e firstNam e streetcitystatezipcode OtherUs er 104BreauxCarroll 76 Main St. ApopkaFL30458 Judy Breaux 104BreauxCarroll 76 Main St. ApopkaFL30458 Cyrus Lambea ux 104BreauxCarroll 76 Main St. ApopkaFL30458 Jean Deaux

10 Representing Relationships as Attributes One-to-many One-to-many –For each one-to-many relationship type R subject class S (one side) subject class S (one side) target class T (many side) target class T (many side) –Add the key attributes of S to the schema of T as foreign keys as foreign keys –Name the foreign key attributes ues the role that S plays in relationship type R ues the role that S plays in relationship type R –Add the attributes of the relationship type R to schema for T One-to-one One-to-one –choose one side and use above rule

11 Representing Relationships as Tables Create a relation schema for the relationship type Create a relation schema for the relationship type –foreign key attributes for the key of the related schema –add attributes of the relationship type

12 Many-to-many Relationship Types Schema: IsChildOf (child, parent) P80 Schema: IsChildOf (child, parent) P80 childparent 358-44-7865269-02-8765 579-98-8778479-98-0098 358-44-7865579-98-8778

13 References Principles of Database Systems with Internet and Java Applications by Greg Riccardi Principles of Database Systems with Internet and Java Applications by Greg Riccardi Fundamentals of Database Systems by Elmasri Navathe Fundamentals of Database Systems by Elmasri Navathe Database Systems The Complete Book by Hector Garcia- Molina, Jeffrey D.Ullman and Jennifer Widom Database Systems The Complete Book by Hector Garcia- Molina, Jeffrey D.Ullman and Jennifer Widom


Download ppt "Chapter 5 The Relational Data Model By Yue Lu CS157B Spring 2008 Instructor: Dr.Lee."

Similar presentations


Ads by Google