Constraints
Constraints
SENIOR
What is a Relation?
y a relation r(R)
( ) is a subset of
dom(A1) X dom(A2) X … X dom(An)
Attribute
Table Relation
Column Attribute/Domain
Row (record) Tuple
Values in a column Domain
Table Definition Schema of a Relation
Populated Table Extension
Characteristics of Relations
y tuples
p have no p
particular order
y ordering of attributes not important
y all values belonging
g g to a p
particular attribute are from
the same domain
y attributes are atomic
y attributes may have a null value
Operations on Relations
Department Facultyy
Code Name Office ID# Name Salary Dept
Course
Number Dept_code Title Professor_ID
Student Enrolled
ID# Name Date of Birth Course# Dept_Code Student_ID
y Example
insert values (554433, “Bob”, 25143.56, “ENGL”) into faculty
Insert (cont’d)
Referential Integrity
g y Constraint:
insert values (554433, “Bob”, 25143.56, “ENGL”)
into employee
Faculty
ID# Name Salary Dept
1234 Mary 2345.67 ENGL
2345 Jane 3246 87
3246.87 HIST
3456 Fred 2876.32 COMP
y The only
y constraint which can be violated is the
referential integrity constraint (i.e. A tuple in
another relation references the tuple that is slated for
d l ti )
deletion).
delete from Faculty where name = “Fred”
(referenced by tuples in Course)
y Also, what if there are two people named “Fred”?
Modify
y Change
g the value for one or more attributes in a
relation
Example:
modify SALARY of Faculty where ID# = 1234 to 30000
y Domain constraints
y Key constraints
y Integrity
g y constraints
{ Entity Integrity Constraint
{ Semantic
S i Integrity
i CConstraint
i
Domain Constraints
y value of a key
y uniquely
q y identifies a tuple
p in a relation
y a superkey K is subset of attributes of R such that:
{ no 2 tuples have same values for K
y A key
y is a minimal superkey;
p y; a superkey
p y from which
we cannot remove any attributes and still be able to
uniquely identify tuples in a relation
y a fforeign
g key
y in R is a set of attributes FK in R
such that FK is a primary key of some other relation
R’
y a foreign key is used to specify a referential integrity
constraint
y Example?
Key examples
Department
p ((code,, name,, phone)
p )
Faculty (name
(name, number
number, office
office, dept_code)
dept code)
C
Course ((name, number,
b dept_code)
d t d )
Semantic Integrity Constraints