All Products
Search
Document Center

Tablestore:Update the configurations of a table

Last Updated:Nov 14, 2024

This topic uses parameters and sample code to describe how to use Tablestore SDK for .NET to update the configurations of a table. You can update the time to live (TTL), max versions, max version offset, and Stream configuration of a data table. You can also update the reserved read and write throughput of a data table in a high-performance instance.

Prerequisites

Parameters

For more information, see Parameters.

API operation

 /// <summary>
 /// Update the configurations of a data table by using TableOptions, ReservedThroughput, or StreamSpecification. 
 /// </summary>
 public UpdateTableResponse UpdateTable(UpdateTableRequest request);

 /// <summary>
 /// The asynchronous mode of UpdateTable. The parameters and calling method are the same as those of UpdateTable. 
 /// </summary>
 public Task<UpdateTableResponse> UpdateTableAsync(UpdateTableRequest request);

Sample code

Update the configurations of a data table

The following sample code provides an example on how to update the configurations of a data table.

public static void UpdateTable()
{
  OTSClient otsClient = Config.GetClient();

  TableOptions tableOptions = new TableOptions();
  // Specify the TTL of data in the data table. A value of -1 specifies that data in the data table never expires. 
  tableOptions.TimeToLive = -1;
  // Specify the maximum number of versions that can be retained for data in each attribute column of the data table. In this example, up to five versions of data can be retained for each attribute column. 
  tableOptions.MaxVersions = 5;
  // Specify the maximum difference between the current system time and the timestamp of the written data. In this example, the maximum difference is set to 86,400 seconds (one day). 
  tableOptions.DeviationCellVersionInSec = 86400
  // Specify that the UpdateRow operation on the data table is allowed. 
  tableOptions.AllowUpdate = true;
  
  UpdateTableRequest request = new UpdateTableRequest("<TABLE_NAME>");
  request.TableOptions = tableOptions;
  try{
    otsClient.UpdateTable(request);
    Console.WriteLine("Update table succeeded.");
  }
  catch (Exception ex)
  {
    Console.WriteLine("Update table failed, exception:{0}", ex.Message);
  }
}

Update the reserved throughput of a data table in a high-performance instance

The following sample code provides an example on how to update the reserved throughput of a data table in a high-performance instance.

public static void UpdateTable()
{
  OTSClient otsClient = Config.GetClient();

  // Set the new reserved read throughput to 1 and the new reserved write throughput to 1. You can set the reserved read and write throughput only to 0 for a data table in a capacity instance. 
  CapacityUnit reservedThroughput = new CapacityUnit(1, 1);
  
  TableOptions tableOptions = new TableOptions();
  tableOptions.AllowUpdate = false;
  tableOptions.TimeToLive = -1;
  
  UpdateTableRequest request = new UpdateTableRequest("<TABLE_NAME>", reservedThroughput);
  request.TableOptions = tableOptions;
  try{
    otsClient.UpdateTable(request);
    Console.WriteLine("Update table succeeded.");
  }
  catch (Exception ex)
  {
    Console.WriteLine("Update table failed, exception:{0}", ex.Message);
  }
}

References

  • For more information about the API operation, see UpdateTable.

  • After you update the configurations of a table, you can perform the following operations: