

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

# 在 Amazon Keyspaces 中建立具有用戶端時間戳記的新資料表
<a name="client-side-timestamps-create-new-table"></a>

請依照這些範例，使用 Amazon Keyspaces AWS 管理主控台、Cassandra 查詢語言 (CQL) 或 建立啟用用戶端時間戳記的新 Amazon Keyspaces 資料表 AWS Command Line Interface

------
#### [ Console ]

**使用用戶端時間戳記建立新的資料表 （主控台）**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home) 開啟 Amazon Keyspaces 主控台。

1. 在導覽窗格中，選擇 **Tables** (資料表)，然後選擇 **Create table** (建立資料表)。

1. 在**資料表詳細資訊區段的建立**資料表頁面上，選取金鑰空間，並提供新資料表的名稱。 ****

1. 在**結構描述**區段中，建立資料表的結構描述。

1. 在**資料表設定**區段中，選擇**自訂設定**。

1. 繼續前往**用戶端時間戳記**。

   選擇**開啟用戶端時間戳記**，以開啟資料表的用戶端時間戳記。

1. 選擇 **Create Table** (建立資料表)。您的資料表會在用戶端時間戳記開啟的情況下建立。

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

**使用 CQL 建立新資料表**

1. 若要使用 CQL 建立啟用用戶端時間戳記的新資料表，您可以使用下列範例。

   ```
   CREATE TABLE my_keyspace.my_table (
      userid uuid,
      time timeuuid,
      subject text,
      body text,
      user inet,
      PRIMARY KEY (userid, time)
   ) WITH CUSTOM_PROPERTIES = {'client_side_timestamps': {'status': 'enabled'}};
   ```

1. 若要確認新資料表的用戶端時間戳記設定，請使用 `SELECT`陳述式來檢閱 `custom_properties`，如下列範例所示。

   ```
   SELECT custom_properties from system_schema_mcs.tables where keyspace_name = 'my_keyspace' and table_name = 'my_table';
   ```

   此陳述式的輸出會顯示用戶端時間戳記的狀態。

   ```
   'client_side_timestamps': {'status': 'enabled'}
   ```

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

**使用 建立新的資料表 AWS CLI**

1. 若要在啟用用戶端時間戳記的情況下建立新的資料表，您可以使用下列範例。

   ```
   ./aws keyspaces create-table \
   --keyspace-name my_keyspace \
   --table-name my_table \
   --client-side-timestamps 'status=ENABLED' \
   --schema-definition 'allColumns=[{name=id,type=int},{name=date,type=timestamp},{name=name,type=text}],partitionKeys=[{name=id}]'
   ```

1. 若要確認新資料表的用戶端時間戳記已開啟，請執行下列程式碼。

   ```
   ./aws keyspaces get-table \
   --keyspace-name my_keyspace \
   --table-name my_table
   ```

   輸出看起來應該與此範例類似。

   ```
   {
       "keyspaceName": "my_keyspace",
       "tableName": "my_table",
       "resourceArn": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/my_keyspace/table/my_table",
       "creationTimestamp": 1662681206.032,
       "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": 1662681206.032
       },
       "encryptionSpecification": {
           "type": "AWS_OWNED_KMS_KEY"
       },
       "pointInTimeRecovery": {
           "status": "DISABLED"
       },
       "clientSideTimestamps": {
           "status": "ENABLED"
       },
       "ttl": {
           "status": "ENABLED"
       },
       "defaultTimeToLive": 0,
       "comment": {
           "message": ""
       }
   }
   ```

------