Bird
0
0

Given the table products with a unique index on sku, what happens when you run this SQL?

medium📝 query result Q13 of 15
SQL - Indexes and Query Performance
Given the table products with a unique index on sku, what happens when you run this SQL?
INSERT INTO products (sku, name) VALUES ('A123', 'Item1');
INSERT INTO products (sku, name) VALUES ('A123', 'Item2');
ASecond insert fails with a duplicate key error
BBoth inserts fail due to unique index
CFirst insert fails, second succeeds
DBoth rows insert successfully
Step-by-Step Solution
Solution:
  1. Step 1: Understand unique index effect on inserts

    The unique index on sku means no two rows can have the same sku value.
  2. Step 2: Analyze the insert statements

    The first insert adds 'A123' successfully. The second tries to insert 'A123' again, violating uniqueness, causing an error.
  3. Final Answer:

    Second insert fails with a duplicate key error -> Option A
  4. Quick Check:

    Duplicate insert = error [OK]
Quick Trick: Duplicate value in UNIQUE column causes insert error [OK]
Common Mistakes:
  • Assuming duplicates are allowed
  • Thinking first insert fails
  • Believing both inserts fail

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes