Bird
0
0

You have two tables:

hard📝 Application Q8 of 15
SQL - Table Relationships
You have two tables:
CREATE TABLE Products (ProductID INT PRIMARY KEY, Name VARCHAR(50));
CREATE TABLE Sales (SaleID INT PRIMARY KEY, ProductID INT, FOREIGN KEY (ProductID) REFERENCES Products(ProductID) ON DELETE SET NULL);
If a product is deleted from Products, what happens to the related ProductID in Sales?
AThe ProductID in Sales is set to NULL.
BThe related Sales rows are deleted.
CThe delete is blocked by the foreign key.
DThe ProductID in Sales remains unchanged.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON DELETE SET NULL action

    This option sets the foreign key column to NULL in child rows when the parent row is deleted.
  2. Step 2: Apply to given tables

    Deleting a Products row sets ProductID to NULL in related Sales rows.
  3. Final Answer:

    The ProductID in Sales is set to NULL. -> Option A
  4. Quick Check:

    ON DELETE SET NULL sets child keys to NULL [OK]
Quick Trick: ON DELETE SET NULL nullifies child foreign keys [OK]
Common Mistakes:
MISTAKES
  • Assuming child rows are deleted
  • Thinking delete is blocked
  • Believing child keys remain unchanged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes