Bird
0
0

You have this SQL statement to add a UNIQUE constraint:

medium📝 Debug Q14 of 15
SQL - Table Constraints
You have this SQL statement to add a UNIQUE constraint:
ALTER TABLE users ADD UNIQUE (username);

But it fails with an error. What is the most likely cause?
AThe username column contains duplicate values already.
BThe UNIQUE keyword is misspelled.
CThe table users does not exist.
DUNIQUE constraints cannot be added after table creation.
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNIQUE constraint requirements

    Adding a UNIQUE constraint requires all existing values in the column to be unique.
  2. Step 2: Identify why ALTER TABLE fails

    If duplicates exist in username, the database rejects the constraint addition with an error.
  3. Final Answer:

    The username column contains duplicate values already. -> Option A
  4. Quick Check:

    Existing duplicates block UNIQUE constraint [OK]
Quick Trick: Check for duplicates before adding UNIQUE constraint [OK]
Common Mistakes:
MISTAKES
  • Assuming UNIQUE keyword spelling error
  • Ignoring existing duplicate data
  • Thinking UNIQUE can't be added after creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes