全部產品
Search
文件中心

Tablestore:刪除單行資料

更新時間:May 12, 2026

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

前提條件

初始化Tablestore Client

方法說明

public DeleteRowResponse DeleteRow(DeleteRowRequest request)

非同步方法呼叫:

public Task<DeleteRowResponse> DeleteRowAsync(DeleteRowRequest request)

DeleteRowRequest參數說明

名稱

類型

說明

tableName(必選)

string

資料表名稱。

primaryKey(必選)

PrimaryKey

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

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

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

condition(必選)

Condition

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

範例程式碼

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

try
{
    // 構造主鍵
    PrimaryKey primaryKey = new PrimaryKey
    {
        { "id", new ColumnValue("row1") }
    };
    // 刪除行資料時必須配置刪除條件 (RowExistenceExpectation.IGNORE,表示不做行存在性判斷)
    Condition condition = new Condition(RowExistenceExpectation.IGNORE);

    // 調用 DeleteRow 方法刪除行資料
    DeleteRowRequest deleteRowRequest = new DeleteRowRequest("test_table", condition, primaryKey);
    DeleteRowResponse deleteRowResponse = client.DeleteRow(deleteRowRequest);
    Console.WriteLine($"RequestId: {deleteRowResponse.RequestID}");
    Console.WriteLine($"Read CU Cost: {deleteRowResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"Write CU Cost: {deleteRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
    Console.WriteLine($"Delete row failed, exception: {ex.Message}");
}

相關文檔

批次更新資料