Tables, Keys & Constraints · Question 10 · Medium

Tables, Keys & Constraints question 10

Table Dept has rows (1, IT) and (2, HR). Table Emp has rows (10, Kiran, dept 1), (11, Leela, dept 1) and (12, Mohan, dept 2). Emp.dept_id is declared as FOREIGN KEY REFERENCES Dept(id) ON DELETE CASCADE. After DELETE FROM Dept WHERE id = 1 runs, how many rows are left in Emp?

  1. 1
  2. 3
  3. 0
  4. 2
Answer and explanation

Answer: A. 1

Explanation: ON DELETE CASCADE deletes the child rows that refer to a deleted parent row. Kiran and Leela belong to department 1 and are removed with it, so only Mohan's row remains.

Previous: Table Member: id | name 1 | Asha 2 | Bala The table Member below already has… · Next: Table Team has rows (1, Mumbai) and (2, Chennai). Table Player has rows…

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