All Products
Search
Document Center

Tablestore:DML operations

Last Updated:May 26, 2026

You can use the SQL INSERT, UPDATE, and DELETE statements to write, update, and delete data in Tablestore non-transactional tables.

Scope

Item

Description

Table type

Only non-transactional tables (tables created without the transaction feature enabled).

Supported DML statements

INSERT, UPDATE, DELETE

Query statements

SELECT and SHOW statements are not subject to DML limitations. For more information, see the SQL query documentation.

Some DML syntax

Clauses such as INSERT IGNORE, ON DUPLICATE KEY UPDATE, and the REPLACE statement are supported only for transactional tables.

Prerequisites

  • You have created a non-transactional table.

  • You have created an SQL mapping for the table using the CREATE TABLE statement.

Note

To execute DML operations as a RAM user, you must grant the user the SQL_DML permission. For more information, see Custom RAM Policy.

Usage

You can execute DML operations on non-transactional tables using the Tablestore console or an SDK. This section shows how to use each method.

Console

  1. Log on to the Tablestore console.

  2. On the Overview page, click the name of an Instance Name.

  3. On the Instances page, click the Query by Executing SQL Statement tab.

  4. In the SQL editor, enter a DML statement and click Execute SQL Statement.

Example: Insert a row.

INSERT INTO my_table VALUES (1, 'value1', 100);

SDK

Java

Use the SyncClient.sqlQuery() method of the Java SDK to execute DML statements. Retrieve the affected rows (getAffectedRows()) and the consumed read/write CUs (getConsumedCapacity()) from the SQLQueryResponse.

Note

You must use SDK version 5.17.11 or later.

SQLQueryRequest request = new SQLQueryRequest("INSERT INTO my_table VALUES (1, 'value1', 100)");
SQLQueryResponse response = client.sqlQuery(request);
long affectedRows = response.getAffectedRows();
Map<String, ConsumedCapacity> consumedCapacity = response.getConsumedCapacity();

Go

Execute DML statements by using the TableStoreClient.SQLQuery() method of the Go SDK. Obtain the number of affected rows (AffectedRows) and the consumed read and write CUs (SQLQueryConsumed) from the SQLQueryResponse.

Note

You must use SDK version v1.9.2 or later.

request := &tablestore.SQLQueryRequest{Query: "INSERT INTO my_table VALUES (1, 1, 100, 'hello')"}
response, err := client.SQLQuery(request)
if err != nil {
    log.Fatal(err)
}
affectedRows := response.AffectedRows
consumed := response.SQLQueryConsumed

INSERT statement

For non-transactional tables, the INSERT statement supports single-row inserts and atomic multi-row batch inserts within the same partition key. If a primary key conflict occurs, the operation returns an error and does not overwrite existing data.

Single-row insert

INSERT INTO user_table VALUES (1, 'value1', 100);

Batch insert in a single partition

Multiple rows that share the same partition key can be atomically inserted in a single batch of up to 200 rows. For example, assume the table structure is user_table(pk1 BIGINT, pk2 VARCHAR(1024), value BIGINT), where pk1 is the partition key. Two rows that both have a partition key pk1 of 1 belong to the same partition and can therefore be atomically inserted in a batch.

INSERT INTO user_table VALUES (1, 'attr1', 100), (1, 'attr2', 200);

Notes

  • Primary key conflict: Inserting a row with an existing primary key returns an error with the error code OTSParameterInvalid and an error message that contains Duplicate entry for key 'PRIMARY'. The existing data is not overwritten.

  • Cross-partition batch inserts: All rows in a batch INSERT statement must have the same partition key.

  • Batch size limit: A batch INSERT statement that contains more than 200 rows is rejected.

  • Affected rows: A successful single-row INSERT returns 1. A successful N-row batch insert returns N. If a primary key conflict occurs, the operation returns an error instead of the number of affected rows.

UPDATE statement

For non-transactional tables, the UPDATE statement supports only single-row updates specified by an equality condition on the full primary key. For a composite primary key, the order of columns in the WHERE clause does not need to match the key's defined column order.

Update with constant values

You can update single or multiple columns simultaneously.

-- Update a single column
UPDATE user_table SET attr_col = 999 WHERE pk_col = 1;

-- Update multiple columns
UPDATE user_table SET c1 = 10, c2 = 20, c3 = 'updated' WHERE id = 1;

-- Update a row with a composite primary key. The order of columns in the WHERE clause can differ from the key definition.
UPDATE user_table SET value = 999 WHERE pk2 = 2 AND pk1 = 1;

Atomic increment and decrement

You can atomically increment or decrement the value of a BIGINT attribute column. This is useful for scenarios such as counters. This operation is supported only for integer attribute columns, not for other types such as DOUBLE, BOOL, or VARCHAR.

-- Increment by 1
UPDATE user_table SET counter = counter + 1 WHERE id = 1;

-- Increment by a specified value
UPDATE user_table SET counter = counter + 10 WHERE id = 1;

-- Decrement
UPDATE user_table SET counter = counter - 5 WHERE id = 1;

Set an attribute column to NULL

Setting an attribute column to NULL effectively deletes it; the system removes the column from the row rather than storing a NULL value.

UPDATE user_table SET attr_col = NULL WHERE pk_col = 1;

Notes

  • The WHERE clause must specify an equality condition for the complete primary key: The following cases are not supported, and an OTSParameterInvalid or OTSUnsupportOperation error is returned:

    • The WHERE clause does not include the full primary key.

    • The WHERE clause uses a condition on a non-primary key column.

    • The WHERE clause uses a range query (such as >, <, or BETWEEN).

    • The WHERE clause uses non-equality conditions such as IN, LIKE, OR, or !=.

    • The WHERE clause includes a condition on an attribute column in addition to the full primary key.

  • Cannot modify primary key columns: The SET clause cannot be used to modify the value of a primary key column.

  • Target row does not exist: An UPDATE operation on a non-existent row completes silently with 0 affected rows. No error is returned.

DELETE statement

For non-transactional tables, the DELETE statement supports only single-row deletions specified by an equality condition on the full primary key. For a composite primary key, the order of columns in the WHERE clause does not need to match the key's defined column order.

-- Delete with a single primary key
DELETE FROM user_table WHERE pk_col = 1;

-- Delete with a string primary key
DELETE FROM user_table WHERE id = 'abc';

-- Delete with a composite primary key
DELETE FROM user_table WHERE pk1 = 1 AND pk2 = 1;

-- Delete with a composite primary key where the order of columns in the WHERE clause differs from the key definition.
DELETE FROM user_table WHERE pk2 = 2 AND pk1 = 1;

Notes

  • The WHERE clause must be an equality condition on the complete primary key: This constraint is the same for UPDATE statements. Missing WHERE clauses, conditions on partial or non-primary key columns, range conditions, the IN, LIKE, or OR operators, or conditions on additional attribute columns are not supported.

  • Target row does not exist: A DELETE operation on a non-existent row completes silently with 0 affected rows. No error is returned.

Limitations

SQL syntax limitations

DML operations on non-transactional tables do not support the following SQL syntax:

Limitation

Operations

Description

No WHERE clause

UPDATE, DELETE

Full primary key required.

WHERE clause with non-primary key columns

UPDATE, DELETE

Only equality conditions on primary key columns are supported.

WHERE clause with a partial primary key

UPDATE, DELETE

Full composite primary key required.

Range conditions (>, <=, BETWEEN)

UPDATE, DELETE

Only equality conditions are supported.

IN clause (multiple values)

UPDATE, DELETE

Only single-value equality matches are supported.

LIKE condition

UPDATE, DELETE

Fuzzy matching is not supported.

OR condition

UPDATE, DELETE

Logical OR is not supported.

!= condition

UPDATE, DELETE

Not-equal conditions are not supported.

IS NULL condition (attribute column)

UPDATE, DELETE

Checking for null values in attribute columns is not supported.

Combined primary key and attribute column conditions

UPDATE, DELETE

Only equality conditions on the primary key are supported.

ORDER BY

UPDATE, DELETE

Sorting is not supported.

LIMIT

UPDATE, DELETE

Limiting the number of rows is not supported.

IGNORE option

UPDATE, DELETE

Ignoring errors is not supported.

Priority settings (e.g., HIGH_PRIORITY)

INSERT, UPDATE, DELETE

Not supported.

Multi-table operations

UPDATE, DELETE

Cross-table operations are not supported.

Partition name specification

INSERT, UPDATE, DELETE

Not supported.

Index hints

UPDATE, DELETE

Index hints are not supported.

INSERT SET syntax

INSERT

INSERT INTO t SET col=val is not supported.

INSERT ... SELECT

INSERT

Inserting from a query result is not supported.

INSERT IGNORE

INSERT

Not supported for non-transactional tables.

ON DUPLICATE KEY UPDATE

INSERT

Not supported for non-transactional tables.

REPLACE

INSERT

Not supported.

Updating primary key columns

UPDATE

The SET clause cannot modify primary key columns.

Number of rows in a batch INSERT

INSERT

A maximum of 200 rows per batch within the same partition key.

Data type limitations

Type

Primary key

Limitations

BIGINT

Yes

The UNSIGNED attribute is not supported. The valid range for a primary key value is -9223372036854775808 to 9223372036854775806 (that is, [-2^63, 2^63 - 2], because Long.MAX_VALUE is a reserved system value and cannot be used).

VARCHAR

Yes

Can be used as a primary key column.

VARBINARY

Yes

Can be used as a primary key column.

DOUBLE

No

Cannot be used as a primary key.

MEDIUMBLOB

No

Cannot be used as a primary key. Can only be used as an attribute column.

MEDIUMTEXT

No

Cannot be used as a primary key.

BOOL / TINYINT(1)

No

The length must be 1. Cannot be used as a primary key.

Column options and constraints

When using CREATE TABLE, only the following column options are supported: PRIMARY KEY, NOT NULL, NULL, DEFAULT VALUE, and ON UPDATE.

Only the PRIMARY KEY constraint is supported.

Special table type limitations

Search-indexed tables and alias tables do not support any DML operations (INSERT, UPDATE, DELETE).

Billing

For non-transactional tables, INSERT, UPDATE, and DELETE are all single-row atomic operations. Before writing data, the system validates the target row (for example, to check if the row exists or if column values have changed). This validation process consumes read CUs.

  • Operations that result in a write: Consumes both read and write CUs.

  • Operations that do not result in a write (for example, an INSERT with a primary key conflict, an UPDATE or DELETE on a non-existent row, or an UPDATE where column values do not change): Consumes only read CUs.