全部產品
Search
文件中心

Tablestore:刪除單行資料

更新時間:Mar 12, 2026

本文介紹如何使用 Node.js SDK 刪除Table Store資料表的單行資料。

前提條件

初始化Tablestore Client

方法說明

deleteRow: function deleteRow(params, callback)

params參數說明

名稱

類型

說明

tableName(必選)

string

資料表名稱。

primaryKey(必選)

Array

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

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

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

condition(必選)

TableStore.Condition

刪除條件,詳情請參見條件更新

transactionId(可選)

string

局部事務ID,用於唯一標識局部事務,詳情請參見局部事務

範例程式碼

以下範例程式碼用於刪除 test_table 表中主索引值為 row1 的行資料。

var params = {
    tableName: 'test_table',
    // 主鍵資訊
    primaryKey: [{ 'id': 'row1' }],
    // 刪除資料時必須配置刪除條件 (TableStore.RowExistenceExpectation.IGNORE,表示不做行存在性判斷)
    condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null)
};

client.deleteRow(params, function (err, data) {
    if (err) {
        console.log('Delete row failed with error: ', err);
        return;
    }
    console.log('RequestId: ', data.RequestId);
    console.log('Read CU Cost: ', data.consumed.capacityUnit.read);
    console.log('Write CU Cost: ', data.consumed.capacityUnit.write);
});

相關文檔

批次更新資料