

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用自訂存留時間 (TTL) 更新資料表
<a name="TTL-how-to-enable-custom-alter"></a>

若要啟用資料表的存留時間自訂設定，以便將 TTL 值套用至個別資料列和資料欄，而無需設定整個資料表的 TTL 預設值，您可以使用下列命令。

**注意**  
`ttl` 啟用 之後，您就無法為資料表停用它。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 啟用資料表的自訂 TTL 設定**
+ 

  ```
  ALTER TABLE {{my_table}} WITH CUSTOM_PROPERTIES={'ttl':{'status': 'enabled'}};
  ```

------
#### [ CLI ]

**使用 啟用資料表的自訂 TTL 設定 AWS CLI**

1. 您可以使用下列命令來更新資料表的自訂 TTL 設定。

   ```
   aws keyspaces update-table --keyspace-name 'myKeyspace' --table-name 'myTable' --ttl 'status=ENABLED'
   ```

1. 若要確認資料表現在已啟用 TTL，您可以使用下列陳述式。

   ```
   aws keyspaces get-table --keyspace-name 'myKeyspace' --table-name 'myTable'
   ```

   陳述式的輸出看起來應該如下例所示。

   ```
   {
       "keyspaceName": "myKeyspace",
       "tableName": "myTable",
       "resourceArn": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/myKeyspace/table/myTable",
       "creationTimestamp": "2024-09-02T11:32:27.349000+00:00",
       "status": "ACTIVE",
       "schemaDefinition": {
           "allColumns": [
               {
                   "name": "id",
                   "type": "int"
               },
               {
                   "name": "date",
                   "type": "timestamp"
               },
               {
                   "name": "name",
                   "type": "text"
               }
           ],
           "partitionKeys": [
               {
                   "name": "id"
               }
           ],
           "clusteringKeys": [],
           "staticColumns": []
       },
       "capacitySpecification": {
           "throughputMode": "PAY_PER_REQUEST",
           "lastUpdateToPayPerRequestTimestamp": "2024-09-02T11:32:27.349000+00:00"
       },
       "encryptionSpecification": {
           "type": "AWS_OWNED_KMS_KEY"
       },
       "pointInTimeRecovery": {
           "status": "DISABLED"
       },
       "ttl": {
           "status": "ENABLED"
       },
       "defaultTimeToLive": 0,
       "comment": {
           "message": ""
       },
       "replicaSpecifications": []
   }
   ```

------