Bird
0
0

Consider the table orders with columns order_id (PRIMARY KEY) and tracking_number with a UNIQUE constraint. What will this query return?

medium📝 query result Q5 of 15
SQL - Table Constraints
Consider the table orders with columns order_id (PRIMARY KEY) and tracking_number with a UNIQUE constraint. What will this query return?

SELECT tracking_number FROM orders WHERE tracking_number = 'ABC123';

Assuming there is exactly one row with tracking_number = 'ABC123'.
AMultiple rows with tracking_number 'ABC123'
BOne row with tracking_number 'ABC123'
CNo rows, because UNIQUE disallows selection
DError due to UNIQUE constraint
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNIQUE constraint effect on data

    UNIQUE ensures no duplicates, so only one row can have 'ABC123'.
  2. Step 2: Analyze SELECT query result

    The query returns the single row matching the tracking number.
  3. Final Answer:

    One row with tracking_number 'ABC123' -> Option B
  4. Quick Check:

    UNIQUE allows single matching row in SELECT [OK]
Quick Trick: UNIQUE means SELECT returns at most one matching row [OK]
Common Mistakes:
MISTAKES
  • Thinking UNIQUE prevents selection
  • Expecting multiple rows with same value
  • Confusing UNIQUE with NOT NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes