全部產品
Search
文件中心

Tablestore:更新表配置

更新時間:Jun 26, 2025

本文介紹如何通過 .NET SDK 更新表的配置資訊。

前提條件

初始化Tablestore Client

方法說明

public UpdateTableResponse UpdateTable(UpdateTableRequest request)

非同步方法呼叫:

public Task<UpdateTableResponse> UpdateTableAsync(UpdateTableRequest request)

UpdateTableRequest參數說明

  • TableName(必選)string:資料表名稱。

  • TableOptions(可選)TableOptions:表配置資訊,包含以下參數。

    名稱

    類型

    說明

    TimeToLive(可選)

    int

    資料生命週期,單位為秒,預設值為-1。

    • 設定為-1時表示資料永不到期,否則取值最低為86400(1天),超出生命週期的資料將會被自動清除。

    • 如果要使用多元索引或二級索引功能,必須將資料生命週期設定為-1,或者將AllowUpdate參數設定為false。

    MaxVersions(可選)

    int

    最大版本數,預設值為1。

    • 如果要使用多元索引或二級索引,最大版本數必須設定為1。

    DeviationCellVersionInSec(可選)

    long

    有效版本偏差,單位為秒。

    • 寫入資料的時間戳記與系統目前時間的差值必須在有效版本偏差範圍內,否則寫入資料將會失敗。

    • 屬性列資料的有效版本範圍為[max(資料寫入時間-有效版本偏差, 資料寫入時間-資料生命週期), 資料寫入時間+有效版本偏差)

    AllowUpdate(可選)

    bool

    是否允許更新。

    • 設定為false時,無法通過UpdateRow()方法更新資料。

  • StreamSpecification(可選)StreamSpecification:Stream配置資訊,包含以下參數。

    名稱

    類型

    說明

    EnableStream(必選)

    bool

    是否開啟Stream。

    ExpirationTime(可選)

    int

    Stream到期時間,表示增量日誌到期時間長度。單位為小時,最大值為168(7天)。

    • EnableStream設定為true時,必須設定ExpirationTime。

  • ReservedThroughput(可選)CapacityUnit預留讀寫輸送量,單位為CU。僅CU模式的高效能型執行個體可以設定為非零值且有效。

說明

調用UpdateTable()方法時,必須設定TableOptions、StreamSpecification、ReservedThroughput中的至少一項。

範例程式碼

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

    // 表配置資訊
    TableOptions tableOptions = new TableOptions();
    // 設定資料生命週期,單位為秒
    tableOptions.TimeToLive = 86400;
    // 設定最大版本數
    tableOptions.MaxVersions = 3;
    // 設定有效版本偏差,單位為秒
    tableOptions.DeviationCellVersionInSec = 86400;
    // 設定是否允許更新
    tableOptions.AllowUpdate = false;
    request.TableOptions = tableOptions;

    // 開啟Stream資訊,並設定Stream到期時間為7天
    StreamSpecification streamSpecification = new StreamSpecification(true);
    streamSpecification.ExpirationTime = 168;
    request.StreamSpecification = streamSpecification;

    // 設定預留讀為0CU,預留寫為0CU(僅CU模式高效能執行個體支援設定資料表的預留讀寫輸送量為非零值)
    CapacityUnit reservedThroughput = new CapacityUnit(0, 0);
    request.ReservedThroughput = reservedThroughput;

    // 調用UpdateTable方法修改表配置
    client.UpdateTable(request);
    Console.WriteLine("Update table succeeded.");
}
catch (Exception ex)
{
    Console.WriteLine($"Update table failed, exception:{ex.Message}");
}