Bird
0
0

Which of the following is the correct syntax to add a PRIMARY KEY constraint to an existing table named users on column user_id?

easy📝 Syntax Q3 of 15
SQL - Table Constraints
Which of the following is the correct syntax to add a PRIMARY KEY constraint to an existing table named users on column user_id?
AALTER TABLE users SET PRIMARY KEY user_id;
BALTER TABLE users ADD PRIMARY KEY (user_id);
CALTER TABLE users ADD CONSTRAINT PRIMARY KEY user_id;
DALTER TABLE users ADD PRIMARY KEY user_id;
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct ALTER TABLE syntax for PRIMARY KEY

    The correct syntax is ALTER TABLE table_name ADD PRIMARY KEY (column_name); with parentheses around the column.
  2. Step 2: Compare options

    Only ALTER TABLE users ADD PRIMARY KEY (user_id); uses correct syntax with ADD PRIMARY KEY and parentheses.
  3. Final Answer:

    ALTER TABLE users ADD PRIMARY KEY (user_id); -> Option B
  4. Quick Check:

    Correct syntax for PRIMARY KEY addition = ALTER TABLE users ADD PRIMARY KEY (user_id); [OK]
Quick Trick: Use ADD PRIMARY KEY (column) with parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses around column
  • Using SET instead of ADD
  • Missing CONSTRAINT keyword or misplacing it

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes