Bird
0
0

You ran this SQL command:

medium📝 Debug Q7 of 15
SQL - Table Constraints
You ran this SQL command:
ALTER TABLE Orders ADD CONSTRAINT FK_Orders_Customers FOREIGN KEY CustomerID REFERENCES Customers(CustomerID);
But it returned a syntax error. What is the most probable cause?
AThe referenced table Customers does not exist
BThe FOREIGN KEY column list is missing parentheses around CustomerID
CThe constraint name FK_Orders_Customers is too long
DThe ALTER TABLE command cannot add foreign keys
Step-by-Step Solution
Solution:
  1. Step 1: Review the syntax for adding a foreign key constraint

    The FOREIGN KEY columns must be enclosed in parentheses.
  2. Step 2: Identify the error in the command

    The command uses FOREIGN KEY CustomerID without parentheses, causing a syntax error.
  3. Final Answer:

    The FOREIGN KEY column list is missing parentheses around CustomerID -> Option B
  4. Quick Check:

    Foreign key columns require parentheses [OK]
Quick Trick: Foreign key columns must be in parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses around foreign key columns
  • Assuming constraint name length causes syntax errors
  • Believing ALTER TABLE cannot add foreign keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes