What is referential integrity, and can you explain the different On Delete actions like CASCADE, SET NULL, and RESTRICT?

Last updated 3 July 2026

  • Referential integrity means a foreign key must match an existing parent key or be NULL, preventing orphaned rows. It is enforced by a FOREIGN KEY constraint.

  • ON DELETE CASCADE deletes matching child rows with the parent. SET NULL keeps the child but nulls its FK (column must be nullable).

  • RESTRICT/NO ACTION block deleting a parent that has children (RESTRICT checks immediately, NO ACTION can defer to end of statement).

  • https://seedfa.st/blog/referential-integrity
  • https://medium.com/@sunnywilson.veshapogu/restrict-vs-cascade-vs-set-null-in-sql-choosing-the-right-foreign-key-rule-6d7c98484710
  • https://www.postgresql.org/docs/current/ddl-constraints.html
  • https://dev.mysql.com/doc/refman/8.4/en/create-table-foreign-keys.html
  • https://www.hackerone.com/blog/navigating-waters-foreign-key-constraints-role-update-and-delete
  • https://www.dbvis.com/thetable/postgres-on-delete-cascade-a-guide/
All SQL interview questions