In Tablestore, you can delete multiple rows of data at the same time based on the primary key information or configure the time to live (TTL) for data in a data table to automatically delete expired data.
Deleted data cannot be recovered. Proceed with caution.
Delete data based on the primary key information
Tablestore allows you to delete multiple rows of data at the same time based on the primary key information. You can perform the following steps to delete multiple rows of data at the same time:
Select a suitable method based on your business requirements to query the primary key information of the data that you want to delete.
To delete the data whose primary key values are in the specified range, call the GetRange operation to query the data and obtain the primary key information of the data. For more information, see Read data.
To delete data that meets specific conditions from a data table for which a search index is created, use the search index to query the data and obtain the primary key information of the data. For more information, see Basic query.
To delete all data from a data table, we recommend that you delete the data table and create a data table that has the same configurations.
You can also call the GetRange operation and set the start primary key to INF_MIN and the end primary key to INF_MAX to scan all data in the table. This way, you can obtain the primary key information of all data in the table. However, this consumes a large amount of computing resources. Proceed with caution.
Call the BatchWriteRow operation to delete multiple rows of data at the same time based on the primary key information of the rows. For more information, see Write data.
Configure the TTL to automatically delete expired data
The TTL is an attribute of data tables that specifies the retention period of data in the data tables. If the data in an attribute column is retained for a period of time that exceeds the TTL, the system automatically deletes the data. If the data in all attribute columns of a row exceeds the TTL, the system automatically deletes the row.
Procedure:
Call the UpdateTable operation to modify the TTL of the data table from which you want to delete data.
ImportantIf a search index or secondary index is created for the data table, the TTL of the search index or secondary index must be smaller than or equal to the TTL of the data table. When you modify the TTL of the data table, make sure that the TTL of the search index or secondary index is smaller than or equal to the TTL of the data table.
Data whose retention period exceeds the TTL is considered invalid data. The system automatically deletes invalid data in an asynchronous manner.
Invalid cannot be read even if the system has not deleted the data yet.