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)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}");
}