全部產品
Search
文件中心

Tablestore:刪除單行資料

更新時間:Jun 26, 2026

Java SDK 按主鍵刪除資料表中的單行資料,支援按條件刪除(如行存在時才刪除),適用於精確清理單條記錄的情境。

前提條件

安裝 Tablestore Java SDK並初始化用戶端。

功能說明

public DeleteRowResponse deleteRow(DeleteRowRequest deleteRowRequest) throws TableStoreException, ClientException

按主鍵定位單行後整行刪除。通過 RowDeleteChange 攜帶主鍵,結果通過 response.getConsumedCapacity() 擷取消耗 CU。

以下樣本刪除資料表 delete_row_demo 中主索引值為 row1 的行。

String tableName = "delete_row_demo";

PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();

RowDeleteChange rowDeleteChange = new RowDeleteChange(tableName, primaryKey);

DeleteRowResponse response = client.deleteRow(new DeleteRowRequest(rowDeleteChange));
System.out.println("RequestId: " + response.getRequestId());
System.out.println("Write CU: " + response.getConsumedCapacity().getCapacityUnit().getWriteCapacityUnit());

關鍵參數

  • tableName(必選):刪除的資料表名稱。

  • primaryKey(必選):主鍵資訊,必須包含全部主鍵列。

參數說明

通過 RowDeleteChange 攜帶單行刪除資訊,各參數說明如下。

名稱

類型

說明

tableName(必選)

String

刪除的資料表名稱。

primaryKey(必選)

PrimaryKey

行的主鍵資訊,包括主鍵列名稱和主索引值。

  • 主鍵列資料類型包括 STRING、INTEGER 和 BINARY。

  • 主鍵個數和類型必須與資料表的主鍵 schema 保持一致。

condition(可選)

Condition

刪除操作的執行條件,詳情請參見條件更新

相關文檔