Upload
albert-sherman
View
223
Download
0
Tags:
Embed Size (px)
Citation preview
Chapter 5 Chapter 5 The Relational Data ModelThe Relational Data Model
By Yue LuBy Yue LuCS157B Spring 2008CS157B Spring 2008Instructor: Dr.LeeInstructor: Dr.Lee
Relational Model Relational Model ConceptsConcepts
The Relational Model of Data is The Relational Model of Data is based on the concept of a based on the concept of a RelationRelation
A A RelationRelation is a is a two-dimensional two-dimensional tabletable– The columns of the table represent The columns of the table represent
attributesattributes– The rows of the table represent The rows of the table represent
entitiesentities
Relational Model Relational Model ConceptsConcepts
A A relation schemarelation schema is the name is the name and the list of attributes of a and the list of attributes of a relationrelation– Grade (studentId, assignmentId, Grade (studentId, assignmentId,
points, dateSubmitted)points, dateSubmitted) A A tupletuple is a row of a table, one is a row of a table, one
value for each attributevalue for each attribute– (101, 102, 92, 2/28/08)(101, 102, 92, 2/28/08)
Model ConceptsModel Concepts
DomainDomain DD is a set of atomic valuesis a set of atomic values– Atomic means that each value is indivisibleAtomic means that each value is indivisible
AttributeAttribute AA is the name of a role played by is the name of a role played by some domainsome domain
Relation schema Relation schema RR is the specification of a is the specification of a relation relation – Given by a name and list of attributesGiven by a name and list of attributes– Degree of a relation is the number of attributesDegree of a relation is the number of attributes
RelationRelation (instance) (instance) r(R)r(R) of a relation schemaof a relation schema– A set of n-tuples, n is degree of relation schemaA set of n-tuples, n is degree of relation schema
Characteristics of Relational Characteristics of Relational ModelModel
Relation is a set of tuplesRelation is a set of tuples– No ordering of tuplesNo ordering of tuples– No duplicate tuplesNo duplicate tuples
no two rows have all the same valuesno two rows have all the same values
Each attribute value is atomicEach attribute value is atomic– So no multiple-valued or composite So no multiple-valued or composite
attributesattributes– called called first normal formfirst normal form
Each relation is a set of assertionsEach relation is a set of assertions– Each represents a factEach represents a fact– Some facts are about relationshipsSome facts are about relationships
Representing E-R Model as Representing E-R Model as RelationsRelations
Entity class Entity class Relation schema Relation schema Entity Entity row of table row of table
– set of all entities of class set of all entities of class table table Attribute Attribute column definition column definition
(attribute)(attribute)– attribute value attribute value table element table element
Relationship type Relationship type – relation schemarelation schema– attribute(s) of relation schemaattribute(s) of relation schema
Example of Relation Schema and Example of Relation Schema and
TableTable Figure 4.2 P75Figure 4.2 P75
– Customer(Customer(accountIDaccountID,lastName,firstName, ,lastName,firstName, street, city, state, zipcode, balance)street, city, state, zipcode, balance)
accountId
lastName
firstName
street city state
zipcode
balance
101 Block Jane 1010 Main St.
Apopka
FL 30458
0.00
102 Hamilton
Cherry 3230 Dade St.
Dade City
FL 30555
4.47
103 Harrison
Kate 103 Dodd Hall
Apopka
FL 30457
30.57
104 Breaux
Carroll 76 Main St.
Apopka
FL 30458
34.58
Attributes are atomicAttributes are atomic
Composite attributes – simple attribute for each field– Customer (accountId, lastName,
firstName, street, city, state, zipcode)
Multi-valued Attributes– Represent as TablesRepresent as Tables– See Figure 4.3
Attributes are atomic Attributes are atomic (cont.)(cont.)
All other attributes values are duplicated All other attributes values are duplicated except OtherUserexcept OtherUser
The key of the schema is the setThe key of the schema is the set {accountId, {accountId, OtherUser}OtherUser}
accounaccountIDtID
lastNalastNameme
firstNafirstNameme
streetstreet citycity statestate zipcodzipcodee
OtherUOtherUserser
104104 BreauxBreaux CarrollCarroll 76 76 Main Main St.St.
ApopkaApopka FLFL 3045830458 Judy Judy BreauxBreaux
104104 BreauxBreaux CarrollCarroll 76 76 Main Main St.St.
ApopkaApopka FLFL 3045830458 Cyrus Cyrus LambeLambeauxaux
104104 BreauxBreaux CarrollCarroll 76 76 Main Main St.St.
ApopkaApopka FLFL 3045830458 Jean Jean DeauxDeaux
Representing Relationships as Representing Relationships as AttributesAttributes
One-to-manyOne-to-many– For each one-to-many relationship type RFor 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 Add the key attributes of S to the schema of T T
as foreign keysas foreign keys
– Name the foreign key attributesName the foreign key attributes ues the role that S plays in relationship type Rues the role that S plays in relationship type R
– Add the attributes of the relationship type R Add the attributes of the relationship type R to schema for Tto schema for T
One-to-oneOne-to-one– choose one side and use above rulechoose one side and use above rule
Representing Relationships as Representing Relationships as TablesTables
Create a relation schema for the Create a relation schema for the relationship typerelationship type– foreign key attributes for the key of foreign key attributes for the key of
the related schemathe related schema– add attributes of the relationship add attributes of the relationship
typetype
Many-to-many Relationship Many-to-many Relationship TypesTypes
Schema: IsChildOf (child, parent) Schema: IsChildOf (child, parent) P80P80
child parent
358-44-7865 269-02-8765
579-98-8778 479-98-0098
358-44-7865 579-98-8778
ReferencesReferences
Principles of Database Systems with Internet and Java Principles of Database Systems with Internet and Java Applications by Greg RiccardiApplications by Greg Riccardi
Fundamentals of Database Systems by Elmasri Fundamentals of Database Systems by Elmasri NavatheNavathe
Database Systems The Complete Book by Hector Database Systems The Complete Book by Hector Garcia-Molina, Jeffrey D.Ullman and Jennifer WidomGarcia-Molina, Jeffrey D.Ullman and Jennifer Widom