All Products
Search
Document Center

Tablestore:Update a single row

Last Updated:Jun 04, 2026

Use the Tablestore .NET SDK to update a single row. You can modify attribute column values, add columns, or delete specific versions or entire attribute columns.

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, including column names and values.

  • Supported data types: STRING, INTEGER, and BINARY.

  • The column count and data types 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. Conditional update.

Sample code

This example updates the row with primary key row1, setting attribute column col1 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}");
}

You can also perform these operations:

  • Add an attribute column.

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

    updateOfAttribute.AddAttributeColumnToDelete("col2");

Related topics