CRUD:Update & Delete

Update & Delete are single item operations. That is unlike Relational SQL statement, DynamoDB does not allow bulk deletes and updates. You MUST provide the primary key for the item.

Condition Expression

Like the PutItem operation, the Update and Delete operations also support the Condition Expression. Operation is carried out in storage only if the Condition Expression evaluates to true.

Consider this item collection in a table with Partition Key set to customer’s email address and Sort Key set to order number. Attribute with the name status holds the status of the order. To delete the cancelled order # 456, we will need to set the Partition Key = customer’s email address and Sort Key = order #. When the delete operation is initiated, the call will be routed to appropriate partition.

The condition expression in the call is saying that delete the order #123 (item) only if its status is Cancelled. The request processing logic will evaluate the Condition Expression before deleting the item. Since the condition will evaluate to false, the item will NOT be deleted from storage. But if the same call is made with Order # 456, it will succeed as the condition expression will evaluate to true.

delete-with-condition