Bird
0
0

Which of the following is the correct way to define a primary key in DynamoDB to support a specific access pattern?

easy📝 Syntax Q12 of 15
DynamoDB - Access Patterns and Query Optimization
Which of the following is the correct way to define a primary key in DynamoDB to support a specific access pattern?
A<code>PrimaryKey: { SortKey: 'UserId' }</code>
B<code>PrimaryKey: { PartitionKey: 'OrderId', SortKey: 'UserName' }</code>
C<code>PrimaryKey: { PartitionKey: 'Date' }</code>
D<code>PrimaryKey: { PartitionKey: 'UserId', SortKey: 'OrderId' }</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall DynamoDB primary key structure

    Primary key can be simple (partition key only) or composite (partition + sort key).
  2. Step 2: Check which option uses valid composite key

    PrimaryKey: { PartitionKey: 'UserId', SortKey: 'OrderId' } correctly defines partition key 'UserId' and sort key 'OrderId', matching common access patterns.
  3. Final Answer:

    <code>PrimaryKey: { PartitionKey: 'UserId', SortKey: 'OrderId' }</code> -> Option D
  4. Quick Check:

    Composite key needs PartitionKey + SortKey [OK]
Quick Trick: Primary key needs partition key; add sort key if needed [OK]
Common Mistakes:
MISTAKES
  • Using sort key without partition key
  • Confusing attribute names for keys
  • Defining only sort key without partition key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes