Bird
0
0

You wrote this SQL to add a primary key constraint:

medium📝 Debug Q6 of 15
SQL - Table Constraints
You wrote this SQL to add a primary key constraint:
ALTER TABLE Customers ADD CONSTRAINT PK_Customers PRIMARY KEY (CustomerID);
But you get an error saying the constraint name already exists. What should you do?
AChange PRIMARY KEY to UNIQUE
BRename the constraint to a unique name and try again
CDrop the Customers table
DRemove the CONSTRAINT keyword
Step-by-Step Solution
Solution:
  1. Step 1: Understand the error cause

    The error indicates the constraint name PK_Customers is already used in the database.
  2. Step 2: Fix by renaming the constraint

    Choose a different, unique constraint name and run the command again.
  3. Final Answer:

    Rename the constraint to a unique name and try again -> Option B
  4. Quick Check:

    Unique constraint names avoid errors = D [OK]
Quick Trick: Use unique names for constraints to avoid conflicts [OK]
Common Mistakes:
MISTAKES
  • Removing CONSTRAINT keyword
  • Dropping tables unnecessarily
  • Changing constraint type incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes