Bird
0
0

Consider a UNIQUE index on columns first_name and last_name in table people. Which insert will violate the UNIQUE constraint?

medium📝 query result Q5 of 15
SQL - Indexes and Query Performance
Consider a UNIQUE index on columns first_name and last_name in table people. Which insert will violate the UNIQUE constraint?
INSERT INTO people (first_name, last_name) VALUES ('John', 'Doe');
INSERT INTO people (first_name, last_name) VALUES ('John', 'Smith');
INSERT INTO people (first_name, last_name) VALUES ('John', 'Doe');
AOnly the second insert violates the UNIQUE constraint
BOnly the third insert violates the UNIQUE constraint
CBoth second and third inserts violate the UNIQUE constraint
DNone of the inserts violate the UNIQUE constraint
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNIQUE index on multiple columns

    The UNIQUE index applies to the combination of first_name and last_name together, not individually.
  2. Step 2: Check each insert's combination

    The first insert adds ('John', 'Doe'). The second inserts ('John', 'Smith') which is unique. The third repeats ('John', 'Doe'), violating the UNIQUE constraint.
  3. Final Answer:

    Only the third insert violates the UNIQUE constraint -> Option B
  4. Quick Check:

    UNIQUE on multiple columns = unique combinations [OK]
Quick Trick: UNIQUE on multiple columns means unique pairs [OK]
Common Mistakes:
  • Thinking each column is unique separately
  • Assuming second insert duplicates first
  • Ignoring combined uniqueness rule

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes