Bird
0
0

If a single-table design uses a composite key with PK as 'CUSTOMER#ID' and SK as 'INVOICE#DATE', what will happen if you query with PK='CUSTOMER#123' and SK='INVOICE#2023-01-01'?

medium📝 query result Q5 of 15
DynamoDB - Access Patterns and Query Optimization
If a single-table design uses a composite key with PK as 'CUSTOMER#ID' and SK as 'INVOICE#DATE', what will happen if you query with PK='CUSTOMER#123' and SK='INVOICE#2023-01-01'?
AReturns no results because SK must be a range condition
BReturns all invoices for customer 123
CReturns the invoice for customer 123 on 2023-01-01
DReturns all customers with invoice date 2023-01-01
Step-by-Step Solution
Solution:
  1. Step 1: Understand query with exact SK

    Querying with exact PK and SK returns the single matching item if it exists.
  2. Step 2: Analyze options

    Returns the invoice for customer 123 on 2023-01-01 correctly states the result. Returns all invoices for customer 123 would require a range or begins_with on SK. Returns all customers with invoice date 2023-01-01 is invalid because PK is fixed. Returns no results because SK must be a range condition is false; exact SK queries are valid.
  3. Final Answer:

    Returns the invoice for customer 123 on 2023-01-01 -> Option C
  4. Quick Check:

    Exact PK and SK query returns one item = D [OK]
Quick Trick: Exact PK and SK returns one item if exists [OK]
Common Mistakes:
MISTAKES
  • Assuming SK must be a range
  • Expecting multiple results with exact SK
  • Confusing PK and SK roles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes