Bird
0
0

You have this SQL statement:

medium📝 Debug Q6 of 15
SQL - Table Relationships
You have this SQL statement:
ALTER TABLE Orders ADD FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID);
But it returns an error. What is a likely cause?
ACustomerID column is missing in Orders table.
BThe Orders table already has a foreign key on CustomerID.
CThe syntax is missing a semicolon.
DThe Customers table does not have CustomerID as a primary or unique key.
Step-by-Step Solution
Solution:
  1. Step 1: Check foreign key requirements

    The referenced column must be a primary key or unique in the referenced table.
  2. Step 2: Identify common error causes

    If Customers.CustomerID is not primary or unique, the foreign key cannot be created, causing an error.
  3. Final Answer:

    The Customers table does not have CustomerID as a primary or unique key. -> Option D
  4. Quick Check:

    Referenced key must be unique or primary = The Customers table does not have CustomerID as a primary or unique key. [OK]
Quick Trick: Referenced key must be unique or primary [OK]
Common Mistakes:
MISTAKES
  • Ignoring uniqueness requirement on referenced key
  • Assuming syntax error without checking keys
  • Overlooking missing columns in tables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes