Bird
0
0

Given the table OrderDetails with composite primary key (order_id, product_id), what will this query return?

medium📝 query result Q13 of 15
SQL - Table Constraints
Given the table OrderDetails with composite primary key (order_id, product_id), what will this query return?
SELECT * FROM OrderDetails WHERE order_id = 101;
ANo rows because both keys must be specified.
BOnly one row with order_id 101 and any product_id.
CAn error because product_id is missing in WHERE clause.
DAll rows where order_id is 101, regardless of product_id.
Step-by-Step Solution
Solution:
  1. Step 1: Understand composite key usage in queries

    Composite keys uniquely identify rows, but queries can filter by any column(s).
  2. Step 2: Analyze the query filter

    The query filters only by order_id = 101, so it returns all rows with that order_id regardless of product_id.
  3. Final Answer:

    All rows where order_id is 101, regardless of product_id. -> Option D
  4. Quick Check:

    Filtering by part of composite key returns matching rows [OK]
Quick Trick: Filtering by part of composite key returns matching rows [OK]
Common Mistakes:
MISTAKES
  • Assuming missing key column causes error
  • Thinking only full composite key filters work
  • Expecting only one row when multiple match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes