SQL - Table ConstraintsWhich of the following is the correct syntax to add a foreign key with ON UPDATE SET NULL in SQL?AFOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE SET NULLBFOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE CASCADECFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE SET NULLDFOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE RESTRICTCheck Answer
Step-by-Step SolutionSolution:Step 1: Identify correct ON UPDATE syntaxThe syntax for foreign key with ON UPDATE SET NULL is: FOREIGN KEY (...) REFERENCES ... ON UPDATE SET NULL.Step 2: Check options for ON UPDATE SET NULLFOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE SET NULL matches the correct syntax exactly. Others either use ON DELETE or different actions.Final Answer:FOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE SET NULL -> Option AQuick Check:ON UPDATE SET NULL syntax = FOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE SET NULL [OK]Quick Trick: ON UPDATE SET NULL sets child keys to NULL on parent update [OK]Common Mistakes:MISTAKESUsing ON DELETE instead of ON UPDATEMixing CASCADE and SET NULL in syntaxOmitting REFERENCES keyword
Master "Table Constraints" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Joins - Self join for hierarchical data - Quiz 13medium LEFT and RIGHT JOIN - LEFT JOIN vs RIGHT JOIN decision - Quiz 1easy Set Operations - Why set operations are needed - Quiz 4medium Subqueries - Nested subqueries - Quiz 2easy Subqueries - Scalar subquery in SELECT - Quiz 8hard Subqueries - Subquery vs JOIN performance trade-off - Quiz 4medium Table Constraints - Constraint naming conventions - Quiz 14medium Table Relationships - Many-to-many with junction tables - Quiz 5medium Views - Dropping and altering views - Quiz 1easy Views - Why views are needed - Quiz 15hard