Lecture4 RelationalModel
Lecture4 RelationalModel
Data Model
DBMS models real world
Data Model is link
between users view of
the world and bits stored
in computer. CUSTOMER (Cust-id: integer, Cust-name: text,
Address: text, Phone#: text)
Many models exist
We will concentrate on
the Relational Model
101001
101100
2
The Relational Model Concepts
Database is a collection of relations
Tables (relations)
Tuples (rows)
Attributes (columns)
Domain
4
Relation
RELATION: A table of values
A relation may be thought of as a set of rows.
A relation may alternately be though of as a set of
columns.
Each row represents a fact that corresponds to a real-
world entity or relationship.
Each row has a value of an item or set of items that
uniquely identifies that row in the table.
Sometimes row-ids or sequential numbers are assigned
to identify the rows in the table.
Each column typically is called by its column name or
column header or attribute name.
5
Relation
A Relation may be defined in multiple ways.
The Schema of a Relation: R (A1, A2, .....An)
Relation schema R is defined over attributes A1, A2, .....An
Each attribute Ai is the name of a role played by some domain
D in the relation schema R.
D is called the domain of Ai and is denoted by dom(Ai).
R is called the name of the relation.
The degree of a relation is the number of attributes n of its
relation schema.
6
Relation Example
For Example -
CUSTOMER (Cust-id, Cust-name, Address, Phone#)
Tuples
A tuple is an ordered set of values
Each value is derived from an appropriate domain.
Each row in the CUSTOMER table may be referred to as a
tuple in the table and would consist of four values.
<632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404) 894-2000">
is a tuple belonging to the CUSTOMER relation.
A relation may be regarded as a set of tuples (rows).
Columns in a table are also called attributes of the relation.
8
Domains
A domain has a logical definition:
e.g., USA_phone_numbers are the set of 10 digit
phone numbers valid in the U.S.
A domain may have a data-type or a format defined for it. The
USA_phone_numbers may have a format: (ddd)-ddd-dddd
where each d is a decimal digit.
E.g., Dates have various formats such as monthname,
date, year or yyyy-mm-dd, or dd mm,yyyy etc.
An attribute designates the role played by the domain.
E.g., the domain Date may be used to define attributes
Invoice-date and Payment-date.
Example
STUDENT(Name, SSN, HomePhone, Address,
OfficePhone, Age, GPA)
10
Definition Summary
Informal Terms Formal Terms
Table Relation
Column Attribute/Domain
Row Tuple
Values in a column Domain
Table Definition Schema of a Relation
11
Cardinality = 5 Degree = 7
12
Characteristics of Relations
Ordering of tuples in a relation r(R): The tuples are not
considered to be ordered, even though they appear to be in
the tabular form.
13
14
Key Constraint
A set of fields is a superkey if:
No two distinct tuples can have same values in all key fields
A set of fields is a key for a relation if :
It is a superkey
No subset of the fields is a superkey
What if there is more than 1 key for a relation?
One of the keys is chosen (by DBA) to be the primary key.
Other keys are called candidate keys.
Primary keys are underlined
E.g.
SSN is a key for Students.
What about Name?
The set {SSN, GPA} is a superkey.
15
Example Schema
16
Relational Database State
17
Entity Integrity
The primary key is used to identify individual
tuples.
The entity integrity constraint states that no
primary key value can be null.
Key constraints and entity constraints are
specified on individual relations.
18
Referential Integrity
The referential integrity constraint is specified
between two relations. It is used to maintain
consistency among tuples of the two relations.
Informally, it states that a tuple in one relation
that refers to another relation must refer to an
existing tuple in that relation.
19
20
Referential Integrity Revisited
What are the referential integrity constraints of
the example database?
A foreign key can refer to its own relation.
Can be shown in the schema diagram as
directed arrows drawn from each foreign key
to the primary key of the referenced relation.
21
22
Update Operations on Relations
INSERT a tuple
DELETE a tuple
MODIFY a tuple
References
Fundamentals of Database Systems, 4th
Edition, by Elmasri and Navathe
Chapter 5
Database Management Systems, Third
Edition by Ramakrishnan and Gehrke
Chapter 3
Database Management Systems, Third
Edition, by A Vaisman
24