Skip to content
Related Articles

Related Articles

GATE | GATE-IT-2004 | Question 78

Improve Article
Save Article
Like Article
  • Last Updated : 28 Jun, 2021

Consider two tables in a relational database with columns and rows as follows:

Table: Student
Roll_noNameDept_id
1ABC1
2DEF1
3GHI2
4JKL3
Table: Department
Dept_idDept_name
1A
2B
3C

Roll_no is the primary key of the Student table, Dept_id is the primary key of the Department table and Student.Dept_id is a foreign key from Department.Dept_id
What will happen if we try to execute the following two SQL statements?

  1. update Student set Dept_id = Null where Roll_on = 1
  2. update Department set Dept_id = Null where Dept_id = 1

(A) Both (i) and (ii) will fail
(B) B) (i) will fail but (ii) will succeed
(C) (i) will succeed but (ii) will fail
(D) Both (i) and (ii) will succeed


Answer: (C)

Explanation:  

  • update Student set Dept_id = Null where Roll_on = 1 ->This will succeed as roll no is primary key and we may set a foreign key NULL
  • update Department set Dept_id = Null where Dept_id = 1 ->As Student table(Roll no 1 and 2) are referring to Dept_id so according to referential integrity constraint we can NOT delete Dept_id.However, Exceptionally we may overcome it if we want using Cascaded Delete option.


Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!