Bird
0
0

Consider these tables:

hard📝 Application Q9 of 15
SQL - Table Constraints
Consider these tables:
CREATE TABLE orders (order_id INT PRIMARY KEY);
CREATE TABLE order_items (
item_id INT PRIMARY KEY,
order_id INT,
FOREIGN KEY (order_id) REFERENCES orders(order_id) ON UPDATE RESTRICT
);

What will happen if you try to update orders.order_id that is referenced by order_items.order_id?
AThe order_items.order_id will be set to NULL.
BThe update will cascade to order_items.order_id.
CThe update will be rejected due to ON UPDATE RESTRICT.
DThe update will succeed and order_items.order_id remains unchanged.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON UPDATE RESTRICT behavior

    ON UPDATE RESTRICT prevents updating parent key if child rows reference it.
  2. Step 2: Apply to orders and order_items

    Trying to update orders.order_id referenced by order_items.order_id will be rejected.
  3. Final Answer:

    The update will be rejected due to ON UPDATE RESTRICT. -> Option C
  4. Quick Check:

    ON UPDATE RESTRICT blocks parent key update [OK]
Quick Trick: ON UPDATE RESTRICT blocks parent key changes [OK]
Common Mistakes:
MISTAKES
  • Thinking update cascades
  • Assuming child keys set to NULL
  • Believing update succeeds without change

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes