Deferred constraint idea using transaction (concept + SQL)
SQL
Medium
6 views
Problem Description
You are inserting parent and child rows in one transaction. Write a safe sequence so the FK does not fail when you insert child first.
Output Format
SQL statements
Sample Test Case
Input:
Parent(id), Child(id, parent_id)
Output:
Successful insert
Constraints
Assume FK exists; insert order matters
Official Solution
BEGIN; INSERT INTO Parent(id) VALUES (10); INSERT INTO Child(id,parent_id) VALUES (1,10); COMMIT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!