Professional Documents
Culture Documents
Lecture 2 - Relational Model
Lecture 2 - Relational Model
Lecture 2 - Relational Model
Relational Model
• In the relational data model
– a database is a set of tables (with additional constraints,
programs and interfaces)
– a schema is the description of tables in a database
– a relation or a table is a “set” of tuples
– a tuple or a record is a mapping from a set of attributes to their
values
– an attribute is a slot for recording data, it has a name and a
domain of applicable values
– the schema of a table contains the table’s name and the
attributes and the domain of the attributes
1
Lecture 2 - Relational Model
• Additional logic:
– BIDS and ITEMS contain all the “unsold” items.
As soon as an item is sold, it is deleted from
bids and items. The loosing bidders are notified
that they lost the item.
Fall 2001 Database Systems 3
78:9;<= 7'>6?@ A BCEDGF ;DGC@ H
Smith@aol.com IKJ L:M-N)O Gray@microsoft,com
³'´'µ3¶ ³K· ¸ µ:¹Eº » ´· ¸ ¼· ¸ ³'½6¾´E¸ ¿ÀGÁ%½%Â/º fegihjk fl m n l m Go pqir set6u/pev/l tew
ÃKÄ ÅKÆ Ç'È%É'Ê ËÆ ÌÆ ÃKÍ ÆÎÊÊ x'y z y 1{ |-}e~ e) E6)}^|
ÃKÄ ÅKÍ Ç'È%É'Ê ËeÏ ÌÉ ÃÐ É'ÊÊ'ÊÊ /6
ÃKÄ ÅÉ Ç'È%ÉKÆ ËÆ ÌÆ ÃKÍ Æ^ÍÊ x' z $Ee6e6
/eeX ie))}-|
ÃKÄ ÅÏ Ñ'ÈEÆ ËEÒ ÌÉ ÃÐ ÍÏKÊ'ÊÊ /
E %}
ÃKÄ ÅÐ Ñ'ÈEÆ ËÆ ÌÆ ÃKÍ Æ^ÍÆ x z $Ee6e6
/eeX Ge
ÃKÄ ÅÒ Ñ'ÈEÍ ËeÏ ÌÉ ÃÏ ÉÐ'Ê'ÊÊ /
E %} Ke
ÃKÄ Å'Ó Ñ'ÈEÍ ËÍ ÌÍ ÃKÆ ÍÐ'Ê % e- )¡%¢-¢ ¡ £$¤E¥ ¥ ¤/¦
ÃKÄ ÅÇ Ñ'È%É ËÍ ÌÍ ÃÉ ÍÊÊ § G ¨¤e©e©ª%« ¯ ¡%¤6¢^¢e¥ ¡
E¥ ¥ ¡E¬)¢6 ®
E° ± e- )¡%¢-¢ ¡ ²E6¦)¢^®
Fall 2001 Database Systems 4
2
Lecture 2 - Relational Model
Attributes - Domains
• All tuples in Owners come from
– D1 × D2 × D3
– An example tuple: <OID:O1, Name: ’Smith’,
Email: ‘smith@aol.com’>
– For any tuple: <OID:v1, Name: v2, Email: v3>
we have the property that v1 ∈ D1, v2 ∈ D2, v3 ∈ D3
• We usually abuse notation and assume an ordering
for the attribute/domain pairs, and write the relation
schema as:
Owners(OID, Name, Email)
and a tuple as:
<O1,’Smith’,’smith@aol.com> ∈ Owners
3
Lecture 2 - Relational Model
More on domains
• A domain is a type in the programming language sense
• Domain values is a set of acceptable values for a
variable of a given type.
– Zipcode: zipcodeDomain = {11111, … ,99999},
– Grants: availableGrants = {50,000, … ,1,000,000}
– Simple/Composite domains
• Address = Street name+street number+city+province+ postal code
• Domain compatibility
– Binary operations (e.g., comparison to one another, addition, etc)
can be performed on them.
• Full support for domains is not provided in many current
relational DBMSs
Relation Instances
• A relation/table instance is a set of tuples with a
specific schema (attribute/domain pairs)
List form:
OWNERS(OID,Name,Email) = { <O1, Smith, smith@aol.com>,
<O2, Johns, johns@geocities.com>, <O3, Brown,
Brown@netmail.com>, <O4, Gray, Gray@microsoft.com> }
4
Lecture 2 - Relational Model
Relational Model
Based on finite set theory:
• First Normal Form Rule: all attributes take simple
values - no set values are allowed.
• Rows are accessed only by their content. The order of
tuples does not have any meaning.
• The order of columns does not have any specific
meaning either.
• No two tuples can have the same values for all the
attributes, i.e. relations are sets.
• Commercial systems allow duplicates (so bag
semantics)
Fall 2001 Database Systems 9
Keys
• A superkey is a set of attributes that help uniquely
identify a specific tuple
– if no two owners may have the same Oid, then Oid
is a superkey
– if no two owners may have the same email
address, then Email is a superkey
• How about:
– Oid + Name (together) for Owners?
– Oid + Name (together) for ITEMS?
– Iid + Oid (together) for ITEMS?
5
Lecture 2 - Relational Model
Keys
• Given relation T, we use t[A1,…,Ak] to denote tuples with only
attributes A1,…,Ak
– for example, if t = <O1, Smith, smith@aol.com> then
t[oid,name] = <O1, Smith>
Null values
• Attributes may be allowed to have null values because
– a value does not exist for a tuple
– a value exists, but it is not known
– it is not known whether a value exists or not