Bird
0
0

You have a UNIQUE index on username. You want to update a row's username to a value that already exists in another row. What happens?

hard📝 Application Q9 of 15
SQL - Indexes and Query Performance
You have a UNIQUE index on username. You want to update a row's username to a value that already exists in another row. What happens?
AThe update sets the username to NULL automatically
BThe update succeeds and duplicates the username
CThe update fails due to UNIQUE constraint violation
DThe update deletes the other row with the duplicate username
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNIQUE index effect on updates

    Updating a UNIQUE indexed column to a duplicate value violates the constraint and causes failure.
  2. Step 2: Analyze the update operation

    The database rejects the update to prevent duplicate usernames.
  3. Final Answer:

    The update fails due to UNIQUE constraint violation -> Option C
  4. Quick Check:

    UNIQUE index blocks duplicate updates [OK]
Quick Trick: Updating to duplicate UNIQUE value causes error [OK]
Common Mistakes:
  • Assuming update overwrites duplicates
  • Thinking update sets value to NULL
  • Believing update deletes other rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes