0% found this document useful (0 votes)
2 views

Relational Model- Practice Problem1-Sol

The document provides practice problems and solutions related to the relational model in database systems, focusing on super keys, foreign key constraints, and operations like delete, insert, and update. It includes specific scenarios with employee and department tables, detailing the effects of different foreign key options (cascading, set NULL, and no action) on various operations. The document serves as a resource for understanding relational database management concepts in a computer science course.

Uploaded by

tfaizanvr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Relational Model- Practice Problem1-Sol

The document provides practice problems and solutions related to the relational model in database systems, focusing on super keys, foreign key constraints, and operations like delete, insert, and update. It includes specific scenarios with employee and department tables, detailing the effects of different foreign key options (cascading, set NULL, and no action) on various operations. The document serves as a resource for understanding relational database management concepts in a computer science course.

Uploaded by

tfaizanvr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

National University of Computer and Emerging Sciences, Lahore Campus

Course: Database Systems


Program: BS(Computer Science)
Instructor: Muhammad Ishaq Raza

Practice Problem: Relational Model (1) - SOLUTION

Question 1:

Question 3:

Page 1 of 7
R

A B C D E

F G H I

A F H I

a. State all the super key(s) for the above relation.


A, B, AB, AC, AD, AE, ABC, ABD, ABE, ACD, ACE, ABCDE, BCD, BCE, BDE, BC, BD, BE
F, FG, FH, FI, FGH, FGI, FHI, FGHI
AF, AFH, AFI, AFHI

b. Mention the super key(s) which are minimal (i.e. key).


A & B in R, F in S, AF in T.

Page 2 of 7
Question 4:

Employee Department

ID Name Salary Department ID


1 Tom 15000 1
2 Pam 20000 3 ID Department_ Name Location
3 John 50000 2 1 CS London
4 Sam 60000 3 2 EE NULL
5 Todd 70000 2 3 BBA New York
6 Neil 10000 NULL 4 Other Department Sydney

*Consider all questions are Independent.


1. For Delete
a. Assume that foreign key with cascading option is implemented.
i. Delete the department(s) whose location is NULL
Department EE will be deleted. All employees who are in EE department will also
be deleted.

ii. Delete the employee(s) whose department id is 3.


The employees with ID 2, 4 will be deleted.

iii. Delete the department having id equal to 4.


The department having id 4 will be deleted. There will be no change in Employee
Table.

b. Assume that foreign key with Set NULL option is implemented.


i. Delete the department whose location is New York.
ID Name Salary Department ID
1 Tom 15000 1
2 Pam 20000 NULL
3 John 50000 2

Page 3 of 7
ID Department_ Name Location
1 CS London
2 EE NULL
4 Sam 60000 NULL 4 Other Department Sydney
5 Todd 70000 2
6 Neil 10000 NULL

ii. Delete the department whose department name is CS


ID Name Salary Department ID
1 Tom 15000 NULL
2 Pam 20000 3 ID Department_ Name Location
3 John 50000 2 2 EE NULL
4 Sam 60000 3 3 BBA New York
5 Todd 70000 2 4 Other Department Sydney
6 Neil 10000 NULL

iii. Delete the employee whose id is 4.


ID Name Salary Department ID
1 Tom 15000 1
ID Department_ Name Location
2 Pam 20000 3
1 CS London
3 John 50000 2
2 EE NULL
5 Todd 70000 2
3 BBA New York
6 Neil 10000 NULL
4 Other Department Sydney

iv. Delete all departments.


ID Name Salary Department ID
1 Tom 15000 NULL
2 Pam 20000 NULL ID Department_ Name Location
3 John 50000 NULL
4 Sam 60000 NULL
5 Todd 70000 NULL
6 Neil 10000 NULL

c. Assume that foreign key with no action is implemented.

Page 4 of 7
i. Delete the department whose location is New York.
Operation not allowed since there are two employees who have this
department id.

ii. Delete the department having id equal to 4.


The department will be deleted. No change in the Employee Table.

iii. Delete the employee(s) having salary greater than 40000.


All employees having salary greater than 40000 will be deleted. No change
in the department table.

2. For Insert
a. Assume that foreign key with cascading option is implemented.
i. Insert <NULL, ‘Physics’, ‘Tokyo’> into Department.
Operation not allowed since the primary key cannot be null.
ii. Insert <7, ‘George’, 54000, 6> into Employee.
Operation not allowed since referential integrity constraint is being violated.
iii. Insert <8, ‘John’, 60000 > into Employee.
Operation will be allowed. The department id of the employee will be set to NULL.
NO change in the department table.

b. Assume that foreign key with set NULL is implemented.


i. Insert <4, ‘Ali’, 100000, 2> into Employee.
Operation not allowed because primary key constraint is being violated.
ii. Insert <NULL, ‘Hameed’, 80000,1> into Employee.
Operation not allowed since primary cannot be NULL.
iii. Insert <5, ‘Physics’, ‘Karachi’ > into Department.
The department will be inserted. No change in the employee table.
iv. Insert < ’7’ , ‘Mathematics’, ‘Sydney’> into Department.

Page 5 of 7
Operation allowed. Character type will be converted to integer by sql.

c. Assume that foreign key with No Action is implemented.


i. Insert <7, ‘Ali’, 40000> into Employee.
Operation allowed. The department id of this employee will be set to NULL.
ii. Insert <10, ‘Umer’, 60000, 6> into Employee.
Operation not allowed since referential integrity constraint is being violated.
iii. Insert <3, ‘Physics’, ‘New York’, 1>
Operation not allowed since primary key constraint is being violated.

3. For Update
a. Assume that foreign key with cascading option is implemented
i. For the department having id=4, change the id to 3.
Operation not allowed since primary key constraint is being violated.
ii. For the department having id=1, change the location to Karachi.
The location of department will be changed from Sydney to Karachi. No change
in the employee table.
iii. For the employee having id=1, change the id to 8.
The id of the employee will be changed from 1 to 8. No change in the department
table.

iv. For the department having id=3, change the id to 10.


ID Name Salary Department
ID
1 Tom 15000 1
2 Pam 20000 10
3 John 50000 2
4 Sam 60000 10
5 Todd 70000 2
6 Neil 10000 NULL

Page 6 of 7
ID Department_ Name Location
1 CS London
2 EE NULL
10 BBA New York
4 Other Department Sydney

b. Assume that foreign key with set NULL option is implemented.


i. For the department having id=1, change the id to 8.
ID Name Salary Department ID
1 Tom 15000 NULL
2 Pam 20000 3 ID Department_ Name Location
3 John 50000 2 8 CS London
4 Sam 60000 3 2 EE NULL
5 Todd 70000 2 3 BBA New York
6 Neil 10000 NULL 4 Other Department Sydney

ii. For department having location as NULL, change the id to 4.


Operation not allowed since primary key constraint is being violated.

iii. For the department having name=’BBA’, change the name to ‘Mathematics’.
The name will be changed. No change in the Employee table.

c. Assume that foreign key with no Action is implemented.


i. For department having department name as NULL, update the department
name to ‘Karachi’.
The name will be changed. No change in the Employee table.

ii. For department having department id=4, update the department id to 3.


Operation not allowed since primary key constraint is being violated.

iii. For department having department id= 1, update the department id to 10.
Operation not allowed since there is an employee whose department id is 1.

iv. For department having department id=4, update the department id to 6


. Operation allowed. No change in the employee table.

Page 7 of 7

You might also like