All Products
Search
Document Center

Tablestore:Basic data operations

Last Updated:Feb 10, 2025

Tablestore provides basic data operations to write, read, and delete data. You can use the Tablestore console, SDKs, and CLI to perform basic data operations. This topic describes the methods that you can use to perform basic data operations and the scenarios of the methods.

Write data

You can use the following methods to write data to data tables: insert a single row of data, update a single row of data, and write multiple rows of data at the same time. When you write data, you can specify a custom data version number and use the conditional update feature to configure the conditions for writing data. For more information, see Write data.

Method

Description

Scenario

Insert a single row of data

You can write a single row of data. If the row exists, Tablestore deletes all versions of data in all columns from the existing row and writes new data.

This method is suitable for scenarios in which you want to write a small amount of data.

Update a single row of data

You can add or remove an attribute column in a row, delete a specific version of data from an attribute column, or update the value of an existing attribute column.

If the row does not exist, a new row is added.

This method is suitable for scenarios in which you want to update a small amount of data.

Write multiple rows of data at the same time

You can write multiple rows of data to one or more tables at the same time.

This method is suitable for scenarios in which you want to write, delete, or update a large amount of data and scenarios in which you want to write, delete, and update data at the same time.

Read data

You can use the following methods to read data from data tables: read a single row of data, read multiple rows of data at the same time, and read data whose primary key values are within a specific range. When you read data, you can specify the columns that you want to return, use the filter feature to filter row data, and specify the version range or a specific version of data that you want to return. For more information, see Read data.

Method

Description

Scenario

Read a single row of data

You can read a single row of data.

This method is suitable for scenarios in which the values of all primary key columns of the row that you want to read can be determined and the number of rows that you want to read is small.

Read multiple rows of data at the same time

You can read multiple rows of data from one or more tables at the same time.

This method is suitable for scenarios in which the values of all primary key columns of the rows that you want to read can be determined and the number of rows that you want to read is large or you want to read data from multiple tables.

Read data whose primary key values are within a specific range

You can read data whose primary key values are within a specific range.

This method is suitable for scenarios in which the range of primary key values or the prefix of primary key values of the rows that you want to read can be determined.

Delete data

You can delete data from data tables by using the following methods: delete a single row of data and delete multiple rows of data at the same time. When you delete data, you can use the conditional update feature to configure the conditions for deleting data. For more information, see Delete data.

Method

Description

Scenario

Delete a single row of data

You can delete a single row of data. If the row that you want to delete does not exist, the data table remains unchanged.

This method is suitable for scenarios in which you want to delete a small amount of data.

Delete multiple rows of data at the same time

After you obtain the primary key information of the rows that you want to delete, you can delete the rows at the same time based on the primary key information.

This method is suitable for scenarios in which you want to delete a large amount of data.

References

  • You can use the conditional update feature to configure the conditions for writing or deleting data. For more information, see Conditional updates.

  • You can use the local transaction feature to perform atomic operations to read or write one or more rows of data. For more information, see Local transactions.

  • You can use the atomic counter feature to collect real-time statistical data for online applications, such as the number of page views (PVs) on various posts. For more information, see Use the atomic counter feature.

  • You can use the filter feature to filter data that meets specific conditions when you read data. For more information, see Configure a filter.

  • You can use the time to live (TTL) feature to automatically delete data whose retention period exceeds the specified TTL value. For more information, see Data versions and TTL.