Bird
0
0

Consider this table creation:

medium📝 Debug Q14 of 15
SQL - Table Relationships
Consider this table creation:
CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT, FOREIGN KEY CustomerID REFERENCES Customers(CustomerID));
What is wrong with this statement?
AForeign key cannot reference Customers table
BCustomerID should be declared as PRIMARY KEY
CPRIMARY KEY must be declared after FOREIGN KEY
DMissing parentheses around the foreign key column name
Step-by-Step Solution
Solution:
  1. Step 1: Check foreign key syntax

    The foreign key column name must be enclosed in parentheses after FOREIGN KEY.
  2. Step 2: Identify the error in the statement

    The statement uses FOREIGN KEY CustomerID without parentheses, which is invalid syntax.
  3. Final Answer:

    Missing parentheses around the foreign key column name -> Option D
  4. Quick Check:

    FOREIGN KEY (col) needs parentheses [OK]
Quick Trick: Always use parentheses around foreign key columns [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses in FOREIGN KEY declaration
  • Misordering PRIMARY and FOREIGN KEY declarations
  • Confusing foreign key with primary key requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes