Bird
0
0

Which SQL statement correctly enforces this?

hard📝 Application Q15 of 15
SQL - Table Constraints
You want to ensure that the combination of first_name and last_name in the employees table is unique, but duplicates are allowed in each column individually. Which SQL statement correctly enforces this?
AALTER TABLE employees ADD UNIQUE (first_name, last_name);
BALTER TABLE employees ADD UNIQUE (first_name); ALTER TABLE employees ADD UNIQUE (last_name);
CALTER TABLE employees ADD UNIQUE first_name, last_name;
DALTER TABLE employees ADD UNIQUE CONSTRAINT employees_unique (first_name);
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-column UNIQUE and analyze options

    A UNIQUE constraint on multiple columns ensures the combination is unique (individual duplicates allowed). "ALTER TABLE employees ADD UNIQUE (first_name, last_name);" correctly adds UNIQUE on the pair. Adding UNIQUE separately disallows individual duplicates; other syntax is wrong or ignores one column.
  2. Final Answer:

    ALTER TABLE employees ADD UNIQUE (first_name, last_name); -> Option A
  3. Quick Check:

    Multi-column UNIQUE = unique pairs [OK]
Quick Trick: Use UNIQUE on multiple columns for combined uniqueness [OK]
Common Mistakes:
MISTAKES
  • Adding UNIQUE on each column separately
  • Using incorrect syntax without parentheses
  • Ignoring the need for combined uniqueness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes