All Products
Search
Document Center

Tablestore:Update the configurations of a table

Last Updated:Jun 09, 2025

This topic describes how to update the configurations of a table by using Tablestore SDK for Java.

Prerequisites

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

Method

public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException

UpdateTableRequest parameters

  • tableName (required) String: the name of the data table.

  • tableOptionsForUpdate (optional) TableOptions: the configuration information. The following table describes the parameters included in the tableOptionsForUpdate parameter.

    Parameter

    Type

    Description

    timeToLive (optional)

    OptionalValue<Integer>

    The time to live (TTL) of data in the data table. Unit: seconds.

    • If you set this parameter to -1, the data never expires. Otherwise, the minimum value is 86400 (one day). Data whose retention period exceeds the TTL is 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)

    OptionalValue<Integer>

    The max number of versions that can be retained for data in each attribute column.

    • If you want to create a search index or secondary index for the data table, you must set this parameter to 1.

    maxTimeDeviation (optional)

    OptionalValue<Long>

    The max version offset. Unit: seconds.

    • The difference between the current system time and the timestamp of written data must be within the max version offset. Otherwise, the data fails to be written.

    • Valid version range for data in an attribute column: [max(Data written time - Max version offset, Data written time - TTL), Data written time + Max version offset).

    allowUpdate (optional)

    OptionalValue<Boolean>

    Specifies whether to allow updates.

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

  • streamSpecification (optional) StreamSpecification: the Stream configuration information. The following table describes the parameters included in StreamSpecification.

    Parameter

    Type

    Description

    enableStream (required)

    boolean

    Specifies whether to enable Stream.

    expirationTime (optional)

    OptionalValue<Integer>

    The Stream validity period, which indicates the duration for which incremental logs are retained. Unit: hours. Maximum value: 168 (seven days).

    • If you set the enableStream parameter to true, you must configure this parameter.

  • reservedThroughputForUpdate (optional) ReservedThroughput: the reserved read/write throughput. Unit: capacity units (CUs). Default value: 0. You can configure this parameter and the parameter settings take effect only for high-performance instances in CU mode.

Note
  • When you call the updateTable() method, you must configure at least one of the following parameters: tableOptionsForUpdate, streamSpecification, and reservedThroughputForUpdate.

  • When you configure the tableOptionsForUpdate parameter, you must configure at least one of the following parameters: timeToLive, maxVersions, maxTimeDeviation, and allowUpdate.

Sample code

The following sample code provides an example on how to update the configurations of the test_table table:

public static void updateTableExample(SyncClient client) {
    UpdateTableRequest request = new UpdateTableRequest("test_table");
    // Set the reserved read throughput to 0 CU and the reserved write throughput to 0 CU.
    ReservedThroughput reservedThroughput = new ReservedThroughput(0, 0);
    request.setReservedThroughputForUpdate(reservedThroughput);

    TableOptions tableOptions = new TableOptions();
    // Specify the maximum number of versions that can be retained for data in an attribute column.
    tableOptions.setMaxVersions(3);
    // Specify the TTL in seconds.
    tableOptions.setTimeToLive(86400);
    // Specify the max version offset in seconds.
    tableOptions.setMaxTimeDeviation(86400);
    // Specify whether to allow updates.
    tableOptions.setAllowUpdate(false);
    request.setTableOptionsForUpdate(tableOptions);

    // Enable Stream and set the Stream validity period to seven days.
    StreamSpecification streamSpecification = new StreamSpecification(true, 168);
    request.setStreamSpecification(streamSpecification);
    
    // Call the updateTable method to modify the table configurations.
    client.updateTable(request);
}

References

For more information, see Modify the configurations of a time series table.