

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Amazon Keyspaces 中使用客户端时间戳创建表
<a name="client-side-timestamps-create-new-table"></a>

按照这些示例使用亚马逊密钥空间、Cassandra 查询语言 (CQL) 或 Amazon Keyspaces 创建启用客户端时间戳的新 Amazon Keyspaces AWS 管理控制台表 AWS Command Line Interface

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

**使用客户端时间戳创建新表（控制台）**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 在导航窗格中，选择**表**，然后选择**创建表**。

1. 在**创建表**页面的**表详细信息**部分中，选择一个键空间并为新表提供一个名称。

1. 在**架构**部分，为您的表创建架构。

1. 在**表设置**部分，选择**自定义设置**。

1. 继续查看**客户端时间戳**。

   选择**打开客户端时间戳**，为表打开客户端时间戳。

1. 选择**创建表**。您的表是在打开客户端时间戳的情况下创建的。

------
#### [ 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": ""
       }
   }
   ```

------