Update table configurations

更新时间: 2026-08-04 22:25:21

Use the Tablestore SDK for Java to update the data lifecycle, maximum number of versions, maximum version offset, update permissions, Stream, and reserved throughput settings of a Wide Column model table.

Prerequisites

Install the Tablestore SDK for Java and initialize the client.

Function description

Call updateTable to update the table options, Stream settings, or reserved throughput of a table. Each request must specify at least one configuration group. If you update TableOptions, specify at least one table option.

public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException

The following sample code updates the data lifecycle, maximum number of versions, maximum version offset, and update permissions of the example_table table.

UpdateTableRequest request = new UpdateTableRequest("example_table");

TableOptions tableOptions = new TableOptions();
tableOptions.setTimeToLive(86400);
tableOptions.setMaxVersions(3);
tableOptions.setMaxTimeDeviation(86400L);
tableOptions.setAllowUpdate(false);
request.setTableOptionsForUpdate(tableOptions);

client.updateTable(request);

Parameters

UpdateTableRequest contains the following parameters.

Name

Type

Description

tableName (required)

String

The name of the table.

tableOptionsForUpdate (optional)

TableOptions

The table configurations to update. Specify at least one table configuration.

streamSpecification (optional)

StreamSpecification

The Stream configuration.

reservedThroughputForUpdate (optional)

ReservedThroughput

The reserved read/write throughput configuration. You can specify non-zero values only for compute-optimized instances in CU mode.

You must specify at least one of tableOptionsForUpdate, streamSpecification, and reservedThroughputForUpdate.

Table configurations

tableOptionsForUpdate is of the TableOptions type and contains the following parameters.

Name

Type

Description

timeToLive (optional)

Integer

The time to live (TTL) of data. Unit: seconds. A value of -1 specifies that data never expires. For other values, the minimum is 86400 (one day). Data that exceeds the TTL is automatically deleted. To use a search index or secondary index, set this parameter to -1 or set allowUpdate to false.

maxVersions (optional)

Integer

The maximum number of versions to retain for each attribute column. To use a search index or secondary index, set this parameter to 1.

maxTimeDeviation (optional)

Long

The maximum version offset. Unit: seconds. The difference between the timestamp of the data and the current system time must be within the maximum version offset. The valid version range for attribute column data is [max(Data write time - Maximum version offset, Data write time - TTL), Data write time + Maximum version offset).

allowUpdate (optional)

Boolean

Specifies whether data can be updated by calling updateRow. If this parameter is set to false, data cannot be updated.

Important

You can set updateFullRow only when you create a table. You cannot modify it by calling updateTable.

Stream configuration

streamSpecification is of the StreamSpecification type and contains the following parameters.

Name

Type

Description

enableStream (required)

Boolean

Specifies whether to enable Stream.

expirationTime (optional)

Integer

The retention period of incremental logs. Unit: hours. Maximum value: 168 (seven days). This parameter is required if enableStream is set to true.

Reserved read/write throughput

reservedThroughputForUpdate is of the ReservedThroughput type and contains the following parameter.

Name

Type

Description

capacityUnit (required)

CapacityUnit

The reserved read/write throughput configuration.

Capacity units

reservedThroughputForUpdate.capacityUnit is of the CapacityUnit type and contains the following parameters.

Name

Type

Description

readCapacityUnit (required)

Integer

The reserved read throughput. Unit: CUs.

writeCapacityUnit (required)

Integer

The reserved write throughput. Unit: CUs.

Scenario examples

Update Stream settings

The following sample code enables Stream for the example_table table and sets the retention period of incremental logs to 168 hours.

UpdateTableRequest request = new UpdateTableRequest("example_table");
request.setStreamSpecification(new StreamSpecification(true, 168));

client.updateTable(request);

Update reserved throughput

Reserved throughput is supported only for compute-optimized instances in CU mode. The following sample code sets both the reserved read throughput and reserved write throughput of the example_table table to 0 CUs.

UpdateTableRequest request = new UpdateTableRequest("example_table");
ReservedThroughput reservedThroughput = new ReservedThroughput(0, 0);
request.setReservedThroughputForUpdate(reservedThroughput);

client.updateTable(request);
上一篇: Create a table 下一篇: Query table information
阿里云首页 表格存储 相关技术圈