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

Tablestore:単一行の書き込み

最終更新日:May 12, 2026

.NET SDK を使用して Tablestore テーブルに単一行を書き込む方法について説明します。

前提条件

Tablestore クライアントの初期化

メソッド

public PutRowResponse PutRow(PutRowRequest request)

非同期メソッド:

public Task<PutRowResponse> PutRowAsync(PutRowRequest request)

PutRowRequest パラメーター

パラメーター

タイプ

説明

tableName (必須)

string

テーブル名。

primaryKey (必須)

PrimaryKey

行のプライマリキー列の名前と値。

  • プライマリキー列で使用できるデータ型は、文字列、整数、バイナリです。

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

columns (任意)

AttributeColumns

属性列 (名前、値、データバージョンを含む)。

  • 属性列で使用できるデータ型は、文字列、整数、バイナリ、DOUBLE、ブールです。

  • デフォルトでは、Tablestore はデータバージョンを自動的に生成します。カスタムバージョンを指定することもできます。詳細については、「データバージョンと生存時間」をご参照ください。

condition (必須)

Condition

書き込み操作の条件。詳細については、「条件付き書き込み」をご参照ください。

サンプルコード

この例では、プライマリキー値が "row1" の行を "test_table" テーブルに書き込みます。

try
{
    // プライマリキーを構築します。
    PrimaryKey primaryKey = new PrimaryKey
    {
        { "id", new ColumnValue("row1") }
    };
    // 書き込み操作の条件を指定します。
    // RowExistenceExpectation.IGNORE は行の存在チェックをスキップします。
    Condition condition = new Condition(RowExistenceExpectation.IGNORE);

    // PutRow メソッドを呼び出して行を書き込みます。
    PutRowRequest putRowRequest = new PutRowRequest("test_table", condition, primaryKey, null);
    PutRowResponse putRowResponse = client.PutRow(putRowRequest);
    Console.WriteLine($"* RequestId: {putRowResponse.RequestID}");
    Console.WriteLine($"* Read CU Cost: {putRowResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"* Write CU Cost: {putRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
    Console.WriteLine($"Put row failed, exception: {ex.Message}");
}
  • 属性列を追加します。

    AttributeColumns columns = new AttributeColumns
    {
        { "col1", new ColumnValue("val1") }
    };
    
    // PutRowRequest を作成します。
    PutRowRequest putRowRequest = new PutRowRequest("test_table", condition, primaryKey, columns);

関連トピック

データの一括書き込み