0
0
DynamoDBquery~5 mins

Why update expressions modify attributes in DynamoDB

Choose your learning style9 modes available
Introduction

Update expressions change data in a DynamoDB item by modifying its attributes. This lets you add, change, or remove information easily.

When you want to change a user's email address in a database without replacing the whole record.
When you need to add a new phone number to a contact's details.
When you want to increase a product's stock count after a sale.
When you want to remove an outdated attribute like a temporary discount.
When you want to update multiple fields in one go without reading and writing the whole item.
Syntax
DynamoDB
SET attribute1 = value1, attribute2 = value2
REMOVE attribute3
ADD attribute4 value4
Use SET to add or change attribute values.
REMOVE deletes attributes from the item.
ADD can increase numbers or add elements to sets.
Examples
Change the email attribute to a new value.
DynamoDB
SET email = :newEmail
Delete the attribute named temporaryDiscount.
DynamoDB
REMOVE temporaryDiscount
Increase the stock attribute by a value.
DynamoDB
ADD stock :increment
Sample Program

This updates the price and description, removes an old feature, and adds to the stock count.

DynamoDB
SET price = :newPrice, description = :newDescription
REMOVE oldFeature
ADD stock :increment
OutputSuccess
Important Notes

Update expressions let you change only what you need, saving time and resources.

Be careful with REMOVE; once an attribute is deleted, it is gone unless you add it back.

ADD works only with numbers and sets, not strings.

Summary

Update expressions modify specific attributes without replacing the whole item.

Use SET to add or change, REMOVE to delete, and ADD to increase numbers or add set elements.

This makes updating data efficient and flexible.