Bird
0
0

You have this table creation:

medium📝 Debug Q14 of 15
SQL - Table Constraints
You have this table creation:
CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT, FOREIGN KEY CustomerID REFERENCES Customers(CustomerID));
What is wrong with this statement?
APRIMARY KEY cannot be used with FOREIGN KEY in the same table
BCustomerID must be declared as PRIMARY KEY
CREFERENCES keyword is not allowed in FOREIGN KEY constraints
DFOREIGN KEY must be declared with parentheses around the column name
Step-by-Step Solution
Solution:
  1. Step 1: Check FOREIGN KEY syntax

    FOREIGN KEY columns must be enclosed in parentheses, like FOREIGN KEY (CustomerID).
  2. Step 2: Identify the error in the statement

    The statement misses parentheses around CustomerID in FOREIGN KEY declaration, causing syntax error.
  3. Final Answer:

    FOREIGN KEY must be declared with parentheses around the column name -> Option D
  4. Quick Check:

    FOREIGN KEY columns need parentheses [OK]
Quick Trick: Always use parentheses around FOREIGN KEY columns [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses around foreign key columns
  • Thinking PRIMARY KEY conflicts with FOREIGN KEY
  • Misunderstanding REFERENCES usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes