Bird
0
0

You tried to add a UNIQUE constraint on column username but got an error. What is the most likely cause?

medium📝 Debug Q14 of 15
SQL - Table Constraints
You tried to add a UNIQUE constraint on column username but got an error. What is the most likely cause?
AThe column <code>username</code> is not indexed
BThe column <code>username</code> contains duplicate values already
CUNIQUE constraints cannot be added after table creation
DThe table does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNIQUE addition failure and evaluate causes

    Adding a UNIQUE constraint fails if existing data violates uniqueness (duplicates exist). "The column username contains duplicate values already" identifies the cause. A non-existent table is unrelated (assuming it exists); UNIQUE can be added later; indexing is irrelevant or automatic.
  2. Final Answer:

    The column username contains duplicate values already -> Option B
  3. Quick Check:

    Duplicates prevent adding UNIQUE constraint [OK]
Quick Trick: Check for duplicates before adding UNIQUE [OK]
Common Mistakes:
MISTAKES
  • Assuming UNIQUE can't be added after creation
  • Ignoring existing duplicate data
  • Confusing indexing with UNIQUE constraint

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes