In SQL, the DELETE
statement removes one or more rows from a table.
Amazon DynamoDB uses the DeleteItem
operation to delete one item at a
time.
Deleting data from a table with
SQL
In SQL, you use the DELETE
statement to delete one or more rows. The
WHERE
clause determines the rows that you want to modify. The
following is an example.
DELETE FROM Music
WHERE Artist = 'The Acme Band' AND SongTitle = 'Look Out, World';
You can modify the WHERE
clause to delete multiple rows. For example,
you could delete all of the songs by a particular artist, as shown in the following
example.
DELETE FROM Music WHERE Artist = 'The Acme Band'
Deleting data from a table in
DynamoDB
In DynamoDB, you can use either the DynamoDB API or PartiQL (a SQL-compatible query language) to delete a single item. If you want to modify multiple items, you must use multiple operations.
With the DynamoDB API, you use the DeleteItem
operation to
delete data from a table, one item at a time. You must specify the
item's primary key values.
{ TableName: "Music", Key: { Artist: "The Acme Band", SongTitle: "Look Out, World" } }
Note
In addition to DeleteItem
, Amazon DynamoDB supports a
BatchWriteItem
operation for deleting multiple
items at the same time.
DeleteItem
supports conditional
writes, where the operation succeeds only if a specific
ConditionExpression
evaluates to true. For example, the
following DeleteItem
operation deletes the item only if it
has a RecordLabel attribute.
{ TableName: "Music", Key: { Artist: "The Acme Band", SongTitle: "Look Out, World" }, ConditionExpression: "attribute_exists(RecordLabel)" }