Tutorial 2 - Solutions

Introduction to Database system (IS230)
Tutorial #2 – Relational Model (SOLUTIONS)
Exercise 1
List the primary keys and foreign keys for every relation schema in the following
database schema.
Relation Schema
Employee
Department
Dept_Locations
Project
Works_On
Dependent
Primary Key
Ssn
Dnumber
Dnumber, Dlocation
Pnumber
Essn, Pno
Essn, Dependent_Name
Page - 1 -
Foreign Keys
Super_Ssn, Dno
Mgr_ssn
Dnumber
Dnum
Essn, Pno
Essn
Exercise 2
Consider the following database:
Determine if any integrity constraints will be violated by each of the following
operations:
1. Insert into DEPARTMENT Values(“Audit”, 7, 998800000, null);
This operation is rejected because it violates the referential
integrity constraint (no EMPLOYEE tuple exists with Ssn =
998800000).
2. Insert into DEPARTMENT Values(“Maintenance”, null, 45345353, 201302-01);
This operation is rejected because it violates the entity integrity
constraint (primary key is null).
3. Update EMPLOYEE Set Super_ssn = 987654321 Where Ssn = 333445555;
This operation is acceptable (no violations).
4. Delete From DEPARTMENT Where Mgr_ssn = 88866555;
This operation is not acceptable because it results in referential
integrity violation: tuples in EMPLOYEE refer to this tuple.
5. Delete from EMPLOYEE where Ssn = 8886665555;
Page - 2 -
This deletion will result in referential integrity violations
because the involved tuple is referenced by tuples from the
EMPLOYEE, DEPARTMENT relations.
Exercise 3
Consider the following relations for a database that keeps track of business trips of
salespersons in a sales office:
SALESPERSON (SSN, Name, Start_Year, Dept_No)
TRIP (SSN, From_City, To_City, Departure_Date, Return_Date, Trip_ID)
EXPENSE (Trip_ID, Account#, Amount)
Specify the foreign keys for this schema, stating any assumptions you make.
Answer:
The schema of this question has the following two foreign keys:
1. the attribute SSN of relation TRIP that references relation SALESPERSON, and
2. the attribute Trip_ID of relation EXPENSE that references relation TRIP.
3. In addition, the attributes Dept_No of relation SALESPERSON and Account# of
relation EXPENSE are probably also foreign keys referencing other relations of
the database not mentioned in the question.
Page - 3 -