すべてのプロダクト
Search
ドキュメントセンター

Tablestore:単一行の更新 Tablestore .NET SDK を使用した単一行のデータ更新

最終更新日:May 12, 2026

このトピックでは、.NET SDK を使用して Tablestore テーブルの単一行を更新する方法について説明します。属性列の値を更新したり、属性列を追加したり、特定のバージョンや属性列全体を削除したりできます。

前提条件

Tablestore クライアントの初期化

メソッド

public UpdateRowResponse UpdateRow(UpdateRowRequest request)

非同期メソッド:

public Task<UpdateRowResponse> UpdateRowAsync(UpdateRowRequest request)

UpdateRowRequest のパラメーター

パラメーター

説明

tableName (必須)

string

テーブルの名前。

primaryKey (必須)

PrimaryKey

更新する行のプライマリキー。プライマリキー列の名前と値が含まれます。

  • プライマリキー列のデータ型は、文字列、整数、またはバイナリです。

  • プライマリキー列の数とデータ型は、テーブルのプライマリキースキーマと一致する必要があります。

updateOfAttribute (必須)

UpdateOfAttribute

更新する属性列と更新操作のタイプ。

condition (必須)

Condition

更新条件。詳細については、「条件付き更新」をご参照ください。

サンプルコード

この例では、プライマリキーが row1 の行にある属性列 col1 の値を changed_val1 に更新します。

try
{
    // プライマリキーを構築します。
    PrimaryKey primaryKey = new PrimaryKey
    {
        { "id", new ColumnValue("row1") }
    };
    // 更新する属性列を定義します。
    UpdateOfAttribute updateOfAttribute = new UpdateOfAttribute();
    updateOfAttribute.AddAttributeColumnToPut("col1", new ColumnValue("changed_val1"));
    // 行を更新する際は、条件を指定する必要があります。(`RowExistenceExpectation.IGNORE` は行の存在チェックをスキップします。)
    Condition condition = new Condition(RowExistenceExpectation.IGNORE);

    // `UpdateRow` メソッドを呼び出して行を更新します。
    UpdateRowRequest updateRowRequest = new UpdateRowRequest("test_table", condition, primaryKey, updateOfAttribute);
    UpdateRowResponse updateRowResponse = client.UpdateRow(updateRowRequest);
    Console.WriteLine($"RequestId: {updateRowResponse.RequestID}");
    Console.WriteLine($"読み取り CU コスト: {updateRowResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"書き込み CU コスト: {updateRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
    Console.WriteLine($"行の更新に失敗しました。例外: {ex.Message}");
}

サンプルコードを変更することで、次の行操作を実行できます。

  • 属性列の追加

    updateOfAttribute.AddAttributeColumnToPut("col2", new ColumnValue("val2"));
  • 属性列全体の削除

    updateOfAttribute.AddAttributeColumnToDelete("col2");

関連トピック