Bird
0
0

You wrote this SQL:

medium📝 Debug Q6 of 15
SQL - Table Relationships
You wrote this SQL:
CREATE TABLE Sales (SaleID INT PRIMARY KEY, ClientID INT, FOREIGN KEY ClientID REFERENCES Clients(ClientID));

Why does this cause an error?
AClients table must be created after Sales table
BClientID must be declared as PRIMARY KEY before referencing
CFOREIGN KEY cannot be used in CREATE TABLE statements
DThe FOREIGN KEY clause is missing parentheses around ClientID
Step-by-Step Solution
Solution:
  1. Step 1: Review foreign key syntax

    The FOREIGN KEY clause requires parentheses around the column name(s).
  2. Step 2: Identify error

    In the statement, FOREIGN KEY ClientID REFERENCES... lacks parentheses around ClientID.
  3. Final Answer:

    The FOREIGN KEY clause is missing parentheses around ClientID -> Option D
  4. Quick Check:

    Foreign key columns must be in parentheses [OK]
Quick Trick: Foreign key columns need parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses in FOREIGN KEY clause
  • Assuming referenced column must be primary key in child table
  • Incorrect table creation order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes