Tables, Keys & Constraints · Question 11 · Medium

Tables, Keys & Constraints question 11

Table Team has rows (1, Mumbai) and (2, Chennai). Table Player has rows (Rohit, team 1), (Surya, team 1) and (Jadeja, team 2). Player.team_id is declared as FOREIGN KEY REFERENCES Team(id) ON DELETE SET NULL. What is true after DELETE FROM Team WHERE id = 1 runs?

  1. Player has 1 row, because Rohit and Surya are deleted
  2. The DELETE is rejected, because players still refer to team 1
  3. Player still has 3 rows, and Rohit and Surya still show team_id 1
  4. Player still has 3 rows, and team_id is NULL for Rohit and Surya
Answer and explanation

Answer: D. Player still has 3 rows, and team_id is NULL for Rohit and Surya

Explanation: ON DELETE SET NULL keeps the child rows but replaces their foreign key value with NULL when the parent row is deleted. No player is deleted, and no row is left pointing at a team that no longer exists.

Previous: Table Dept has rows (1, IT) and (2, HR). Table Emp has rows (10, Kiran, dept… · Next: Table Emp: id | name | salary 1 | Asha | 42000 2 | Bala | 65000 3 | Chirag |…

Practise tables, keys & constraints

Try a fresh set of tables, keys & constraints questions with an explanation after every answer, free and without signing up: Tables, Keys & Constraints practice. Or sit a full placement mock test.

More tables, keys & constraints questions

More sql practice

DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge