In DynamoDB, when you use an UpdateExpression with the SET action, what happens to the specified attribute?
Think about whether SET replaces or preserves existing values.
The SET action in an UpdateExpression either creates the attribute if it is missing or replaces the existing value with the new one.
Given an item with attribute status set to "active", what will be the result after applying this UpdateExpression?
REMOVE status
Consider what REMOVE does to attributes in DynamoDB.
REMOVE deletes the specified attribute entirely from the item, so it no longer exists after the update.
Which UpdateExpression correctly increments the numeric attribute counter by 1?
Remember the syntax for arithmetic operations in UpdateExpression.
The correct syntax to increment is SET counter = counter + :inc. The ADD action is used differently and requires a number or set, but the question asks for UpdateExpression syntax.
What is the main advantage of using an UpdateExpression to modify attributes instead of reading the item with GetItem and then writing it back with PutItem?
Think about atomicity and efficiency in database operations.
UpdateExpression modifies attributes atomically in a single request, reducing network overhead and avoiding race conditions compared to separate GetItem and PutItem calls.
Consider this UpdateExpression:
SET #attr = :val
with ExpressionAttributeNames = {"#attr": "score"} and ExpressionAttributeValues = {":val": 10}.
Why might this update not change the score attribute?
Remember which attributes DynamoDB allows to be updated.
Attributes that are part of the primary key (partition key or sort key) cannot be updated. Attempting to do so will fail silently or with an error depending on the SDK.