CS FundamentalsVery hardGATE CS (PYQ pattern)

Relations R(A, B, C) with key A and S(C, D) with key C, where R.C is a foreign key to S. A row of S that is referenced by some R rows is deleted. Which referential action leaves the database consistent while keeping the R rows (and not deleting them)?

  1. A. ON DELETE CASCADE
  2. B. NO ACTION (the delete succeeds immediately)
  3. C. Do nothing; foreign keys are not checked on deletes
  4. D. ON DELETE SET NULL (if R.C allows NULL) or SET DEFAULT with a valid default

Correct answer: D. ON DELETE SET NULL (if R.C allows NULL) or SET DEFAULT with a valid default

CASCADE would delete the R rows; NO ACTION/RESTRICT would reject the delete. SET NULL (or SET DEFAULT to an existing key) keeps the R rows while removing the dangling reference.

More DBMS and SQL questions

Exams that ask this topic