All Products
Search
Document Center

Tablestore:Update the configurations of a table

Last Updated:Jul 08, 2025

This topic describes how to update table configurations using Tablestore SDK for .NET.

Prerequisites

A client is initialized. For more information, see Initialize a Tablestore client.

Method description

public UpdateTableResponse UpdateTable(UpdateTableRequest request)

Asynchronous method:

public Task<UpdateTableResponse> UpdateTableAsync(UpdateTableRequest request)

UpdateTableRequest parameters

  • TableName (required) string: the name of the data table.

  • TableOptions (optional) TableOptions: the table configuration information, which includes the following parameters.

    Parameter

    Type

    Description

    TimeToLive (optional)

    int

    The time to live (TTL) of data in the data table in seconds. The default value is -1.

    • If you set this parameter to -1, data never expires. Otherwise, the minimum value is 86400 (one day). Data whose retention period exceeds the TTL will be automatically deleted.

    • If you want to use search index or secondary index features, you must set this parameter to -1 or set the AllowUpdate parameter to false.

    MaxVersions (optional)

    int

    The maximum number of versions. The default value is 1.

    • If you want to use search index or secondary index features, you must set this parameter to 1.

    DeviationCellVersionInSec (optional)

    long

    The maximum version offset in seconds.

    • The difference between the current system time and the timestamp of written data must be within the maximum version offset range. Otherwise, the data write will fail.

    • The valid version range for attribute column data is [max(Data written time - Maximum version offset, Data written time - TTL), Data written time + Maximum version offset).

    AllowUpdate (optional)

    bool

    Indicates whether updates are allowed.

    • If you set this parameter to false, you cannot update data by using the UpdateRow() method.

  • StreamSpecification (optional) StreamSpecification: the Stream configuration information, which includes the following parameters.

    Parameter

    Type

    Note

    EnableStream (required)

    bool

    Specifies whether to enable Stream.

    ExpirationTime (optional)

    int

    The Stream expiration time, which represents the duration for which incremental logs are retained. The unit is hours. The maximum value is 168 (Seven days).

    • When EnableStream is set to true, you must specify ExpirationTime.

  • ReservedThroughput (optional) CapacityUnit: reserved read and write throughput, in CU. You can set this parameter to a non-zero value and the setting takes effect only for data tables in high-performance instances in CU mode.

Note

When you call the UpdateTable() method, you must specify at least one of TableOptions, StreamSpecification, or ReservedThroughput.

Sample code

try
{
    UpdateTableRequest request = new UpdateTableRequest("test_table");

    // Table configuration information.
    TableOptions tableOptions = new TableOptions();
    // Specify the TTL in seconds.
    tableOptions.TimeToLive = 86400;
    // Specify the maximum number of versions.
    tableOptions.MaxVersions = 3;
    // Specify the maximum version offset in seconds.
    tableOptions.DeviationCellVersionInSec = 86400;
    // Specify whether updates are allowed.
    tableOptions.AllowUpdate = false;
    request.TableOptions = tableOptions;

    // Enable Stream and set the Stream validity period to seven days.
    StreamSpecification streamSpecification = new StreamSpecification(true);
    streamSpecification.ExpirationTime = 168;
    request.StreamSpecification = streamSpecification;

    // Set reserved read throughput to 0 CU and reserved write throughput to 0 CU (you can set this parameter to a non-zero value and the setting takes effect only for data tables in high-performance instances in CU mode).
    CapacityUnit reservedThroughput = new CapacityUnit(0, 0);
    request.ReservedThroughput = reservedThroughput;

    // Call the UpdateTable method to modify the table configurations.
    client.UpdateTable(request);
    Console.WriteLine("Update table succeeded.");
}
catch (Exception ex)
{
    Console.WriteLine($"Update table failed, exception:{ex.Message}");
}