Chapter 5
Chapter 5
(student entity)
From the same domain play different role
* value unknown
* attribute does not apply to this tuple
* this tuple has no value for this attribute
2 Characteristics of Relations
Ordering of tuples in a relation r(R): No order
The tuples are not considered to be ordered, even though they
appear to be in the tabular form. c.f. sequential file
t [Name]=<‘Barbara Benson’>
t [SSN, GPA, Age]=<‘533-69-1238’, 3.25, 19>
3 Relational Integrity Constraints
Constraints are conditions that must hold on all valid
relation instances. There are four main types of constrains:
Domain constraints, Key constraints, Entity integrity
constraints, and Referential integrity constraints.
functional dependencies, ...
Relational Database Schema: A set S of relation
schemas that belong to the same database and a set of
integrity constraints IC. S is the name of the database.
R={R1,R2,…,Rn}
Allow attribute that represent the same real world concept to have
name that may or may not identical in different relation.
Allow attributes that represent different concept to have the same name
in different relations.
(to 7-16)
Figure 7.6 A relational database instance (state) of COMPANY schema
Continued
Note: Other attributes of R may be similarly constrained to
Disallow null values, even though they are not members of the
primary key.
R1
referencing relation
‧‧‧ FK ‧‧‧
R2
PK referenced relation
7-18
4 Update Operations on Relations
Operations: retrievals and updates
-- INSERT a tuple.
-- DELETE a tuple.
-- MODIFY a tuple.
-- Integrity constraints should not be violated by the update operations.
-- Several update operations may have to be grouped together.
-- Updates may propagate to cause other updates automatically.
This may be necessary to maintain integrity constraints.
-- In case of integrity violation, several actions can be taken:
-cancel the operation that causes the violation
-perform the operation but inform the user of the violation
-trigger additional updates so the violation is corrected
-execute a user-specified error-correction routine
Insert operation
Domain Constraint:
if an attribute value is given that does not appear in the domain
Key Constraint:
if a key value in the new tuple t already exists in another tuple in
the relation.
Entity Integrity:
if the primary key of new tuple is null
Referential Integrity:
if the value of any foreign key in t refers to a tuple that does not
exist in the referenced relation.
(See 7-14)
1.Insert < ‘Cecilia’, ’F’, ‘ Kolowsky’, ‘677678989’, ’05-APR-50’,‘6357
Windy Lane, Katy, TX’, F, 28000, null, 4 > into EMPLOYEE.
acceptable
2.Insert <‘Alicia’,’J’,’Zelaya’,’999887777’,’05-APR-50’,’6357 Windy
Lane, Katy,TX’, F, 28000,’987654321’,4> into EMPLOYEE.
Violate key constraint.
3.Insert <‘Cecilia’,’F’,’Kolowsky’,null,’05-APR-50’,’6357 Windy Lane,
Katy,TX’, F, 28000, null,4> into EMPLOYEE.
Violate entity integrity constraint
4.Insert<‘Cecilia’, ‘F’, ‘Kolowsky’,’677678989’,’05-APR-50’,’6357
Windswept Katy, TX, F, 28000, ‘987654321’,7> into EMPLOYEE
Violate referential integrity constraint
EMPLOYEE
‧‧‧ SSN ‧‧‧ SUPER SSN DNo
relations
DECLARE RELATION EMPLOYEE
FOR SCHEMA COMPANY
ATTRIBUTES FNAME DOMAIN PERSON_NAMES,
MINIT DOMAIN PERSON_INITIALS,
LNAME DOMAIN PERSON_NAMES,
SSN DOMAIN PERSON_SSNS,
BDATE DOMAIN DATES,
ADDRESS DOMAIN ADDRESSES,
SEX DOMAIN PERSON_SEX,
SALARY DOMAIN PERSON_SALARIES,
SUPERSSN DOMAIN PERSON_SSNS,
DNO DOMAIN DEPT_NUMBERS