All Products
Search
Document Center

Tablestore:Delete a single row of data

Last Updated:Jun 27, 2025

This topic describes how to use Tablestore SDK for Java to delete a single row of data from a Tablestore table.

Prerequisites

A client is initialized. For more information, see Initialize a Tablestore client.

Method

public DeleteRowResponse deleteRow(DeleteRowRequest deleteRowRequest) throws TableStoreException, ClientException

DeleteRowRequest parameters

  • rowChange (required) RowDeleteChange: The information about the row to be deleted, including the following parameters.

    Parameter

    Type

    Description

    tableName (required)

    String

    The name of the data table.

    primaryKey (required)

    PrimaryKey

    The primary key information, including the primary key column names and values.

    • The data types of primary key columns include STRING, INTEGER, and BINARY.

    • The number and types of primary key columns that you specify must be consistent with those defined in the table.

    condition (optional)

    Condition

    The deletion condition. For more information, see Perform conditional updates.

Sample code

The following sample code deletes a row with the primary key value of row1 from the test_table table.

public static void deleteRowExample(SyncClient client) {
    // Construct the primary key.
    PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
    primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
    PrimaryKey primaryKey = primaryKeyBuilder.build();

    // Construct the row data to be deleted.
    RowDeleteChange rowDeleteChange = new RowDeleteChange("test_table", primaryKey);

    // Call the deleteRow method to delete the row data.
    DeleteRowRequest deleteRowRequest = new DeleteRowRequest(rowDeleteChange);
    DeleteRowResponse deleteRowResponse = client.deleteRow(deleteRowRequest);

    // Return the result.
    System.out.println("RequestId: " + deleteRowResponse.getRequestId());
    System.out.println("Read CU Cost: " + deleteRowResponse.getConsumedCapacity().getCapacityUnit().getReadCapacityUnit());
    System.out.println("Write CU Cost: " + deleteRowResponse.getConsumedCapacity().getCapacityUnit().getWriteCapacityUnit());
}

References