National University of Computer and Emerging Sciences, Lahore Campus
Course: Database Systems
Program: BS(Computer Science)
Instructor: Muhammad Ishaq Raza
Practice Problem: Relational Model (3) - SOLUTION
Consider the following relational database state. Primary keys (PKs) are underlined and foreign keys (FKs) are in italic font.
Assume referential integrity constraint(RIC) on FKs ([Link] and [Link]) are ON DELETE CASCADE and ON UPDATE
SET NULL.
Users Sites Entries
userID popularity name siteID siteName ownerID viewCount entryID siteID rating createdDate tag
23 4 Isbah 3 FAN 22 200 1 3 5 2018-05-11 BP
31 1 Izaan 5 W3Schools 13 400 2 3 10 2018-08-11 Views
13 4 Tahreem 6 Online DB 22 300 3 5 15 2018-05-11
22 5 Khadija 8 SQL Guru 23 250 4 8 10 2018-07-11
5 6 19 2018-05-11 FR
6 8 4 2018-05-17 Views
Q. Apply following operations on the above database. State if the operation would be carried out successfully or not. Explain
your answer briefly. In case of successful operation indicate the changes that will be made to the above database and in case of
Reject state the error that occurred. Please note that all operations are independent.
a. UPDATE users SET userID=55 WHERE popularity=4;
Accept Explain: Multiple entries have popularity =4, thus when we update their userID to 55, the key constraint will
Reject be violated.
b. UPDATE entries SET siteID = 1 WHERE rating=10;
Accept Explain: Referential constraint violated, no site with siteID 1 exists.
Reject
c. DELETE FROM entries WHERE siteID=3;
Accept Explain: First two tuples of entries table are deleted.
Reject
d. DELETE FROM sites WHERE ownerID=22
Accept Explain: referential action is cascade on delete, this will lead to deletion of site 3 and 6 in sites and deletion
Reject of entries 1,2,5 from Entries table.
e. INSERT INTO entries VALUES (6,7 ,5, 2012-05-11, 115);
Accept Explain: key constraint (6), referential constraint (as there is no value= 7 in sites table) and domain
Reject constraint (115 not a string) are violated.
Department of Computer Science Page 1 of 1