Professional Documents
Culture Documents
Lecture 3 - Relational Model & Relational Database Constraints
Lecture 3 - Relational Model & Relational Database Constraints
Lecture 3 - Relational Model & Relational Database Constraints
Example:
CUSTOMER (Cust-id, Cust-name, Address, Phone#)
CUSTOMER is the relation name
Phone#
Each attribute has a domain or a set of valid values which is denoted
by dom(Ai)
For example, the domain of Cust-id is 6 digit numbers.
to that attribute
Example: The domain Date may be used to define two attributes
named “Invoice-date” and “Payment-date” with different meanings
We have,
t[Name] = <‘Barbara Benson’>, and
t[Ssn, Gpa, Age] = <‘533-69-1238’, 3.25, 19>.
Superkey of R:
Is a set of attributes SK of R
with the following condition:
No two tuples in any valid
relation state r(R) will have
the same value for SK
That is, for any distinct
tuples t1 and t2 in r(R),
t1[SK] t2[SK]
This condition must hold in
any valid state r(R)
Key of R:
A "minimal" superkey
That is, a key K is a superkey such that removal of any attribute
from K results in a set of attributes that is not a superkey (does
not possess the superkey uniqueness property)
A Key is a Superkey but not vice versa. A superkey may be a
key (if it is minimal) or may not be a key (if it is not minimal).
Any set of attributes that includes Ssn—for example, {Ssn, Name, Age}—is
a superkey.
The primary key value is used to uniquely identify each tuple in a relation
Provides the tuple identity
Primary key : It is a set of values which uniquely identify the table for
retrieval of information from that table. It is common to designate one of the
candidate keys as the primary key of the relation.
Foreign key : If we are referring a primary key of one table to another then
we call it as foreign key.
Alternate key : All the candidate keys which are not chosen as the primary
key are called alternate keys.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 37
Foreign Key
Constraints
Key Constraints No two tuples in any valid relation state r(R) will have the
same value for Super Keys. If a relation has several
candidate keys, one is chosen arbitrarily to be the primary
key which is used to uniquely identify each tuple in a
relation.
Referential integrity constraint A tuple in one relation that refers to another relation must
refer to an existing tuple in that relation
Domain Constraint Each table has certain set of columns and each
column allows a same type of data, based on its data
type. The column does not accept values of any other
data type.
Operation:
Insert <‘Alicia’, ‘J’, ‘Zelaya’, ‘999887777’, ‘1960-04-05’, ‘6357 Windy Lane, Katy,
TX’, F, 28000, ‘987654321’, 4> into EMPLOYEE.
Result: This insertion violates the key constraint because another tuple with
the same Ssn value already exists in the EMPLOYEE relation, and so it is rejected.
Operation:
Delete the EMPLOYEE tuple with Ssn = ‘999887777’.
Result: This deletion is not acceptable, because there are tuples in
WORKS_ON that refer to this tuple. Hence, if the tuple in EMPLOYEE is deleted,
referential integrity violations will result