All Products
Search
Document Center

Tablestore:Update a single row

最終更新日:May 12, 2026

This topic describes how to use the .NET SDK to update a single row in a Tablestore table. You can update the values of attribute columns, add attribute columns, or delete a specific version or an entire attribute column.

Prerequisites

Initialize a Tablestore client

Method

public UpdateRowResponse UpdateRow(UpdateRowRequest request)

Asynchronous method:

public Task<UpdateRowResponse> UpdateRowAsync(UpdateRowRequest request)

UpdateRowRequest parameters

Parameter

Type

Description

tableName (Required)

string

The name of the table.

primaryKey (Required)

PrimaryKey

The primary key of the row to update. It includes the names and values of the primary key columns.

  • The data types for primary key columns can be STRING, INTEGER, or BINARY.

  • The number and data types of the primary key columns must match the table's primary key schema.

updateOfAttribute (Required)

UpdateOfAttribute

The attribute columns to update and the type of update operation.

condition (Required)

Condition

The update condition. For more information, see Conditional update.

Sample code

This example updates the row whose primary key value is row1 by changing the value of the col1 attribute column to changed_val1.

try
{
    // Construct the primary key.
    PrimaryKey primaryKey = new PrimaryKey
    {
        { "id", new ColumnValue("row1") }
    };
    // Define the attribute columns to update.
    UpdateOfAttribute updateOfAttribute = new UpdateOfAttribute();
    updateOfAttribute.AddAttributeColumnToPut("col1", new ColumnValue("changed_val1"));
    // You must specify a condition when updating a row. (RowExistenceExpectation.IGNORE skips the row existence check.)
    Condition condition = new Condition(RowExistenceExpectation.IGNORE);

    // Call the UpdateRow method to update the row.
    UpdateRowRequest updateRowRequest = new UpdateRowRequest("test_table", condition, primaryKey, updateOfAttribute);
    UpdateRowResponse updateRowResponse = client.UpdateRow(updateRowRequest);
    Console.WriteLine($"RequestId: {updateRowResponse.RequestID}");
    Console.WriteLine($"Read CU Cost: {updateRowResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"Write CU Cost: {updateRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
    Console.WriteLine($"Update row failed, exception: {ex.Message}");
}

Modify the sample code to perform the following row operations:

  • Add an attribute column.

    updateOfAttribute.AddAttributeColumnToPut("col2", new ColumnValue("val2"));
  • Delete an entire attribute column.

    updateOfAttribute.AddAttributeColumnToDelete("col2");

Related topics