在 Azure Cosmos DB Cassandra API 中创建容器Create a container in Azure Cosmos DB Cassandra API

适用于: Cassandra API

本文介绍在 Azure Cosmos DB Cassandra API 中创建容器的不同方式。This article explains the different ways to create a container in Azure Cosmos DB Cassandra API. 它演示了如何使用 Azure 门户、Azure CLI、PowerShell 或受支持的 SDK 来创建容器。It shows how to create a container using Azure portal, Azure CLI, PowerShell, or supported SDKs. 本文演示如何创建容器、指定分区键和预配吞吐量。This article demonstrates how to create a container, specify the partition key, and provision throughput.

本文介绍在 Azure Cosmos DB Cassandra API 中创建容器的不同方式。This article explains the different ways to create a container in Azure Cosmos DB Cassandra API. 如果你使用其他 API,请参阅适用于 MongoDB 的 APIGremlin API表 APISQL API 文章来创建容器。If you are using a different API, see API for MongoDB, Gremlin API, Table API, and SQL API articles to create the container.

备注

创建容器时,请确保不创建名称相同但大小写不同的两个容器。When creating containers, make sure you don't create two containers with the same name but different casing. 这是因为 Azure 平台的某些部分不区分大小写,这可能会对具有此类名称的容器导致遥测和操作混乱/冲突。That's because some parts of the Azure platform are not case-sensitive, and this can result in confusion/collision of telemetry and actions on containers with such names.

使用 Azure 门户进行创建Create using Azure portal

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 创建新的 Azure Cosmos 帐户或选择现有的帐户。Create a new Azure Cosmos account, or select an existing account.

  3. 打开“数据资源管理器”窗格,然后选择“新建表” 。Open the Data Explorer pane, and select New Table. 接下来,请提供以下详细信息:Next, provide the following details:

    • 表明要创建新密钥空间还是使用现有密钥空间。Indicate whether you are creating a new keyspace, or using an existing one.
    • 输入表名称。Enter a table name.
    • 输入属性并指定一个主键。Enter the properties and specify a primary key.
    • 输入要进行预配的吞吐量(例如,1000 RU)。Enter a throughput to be provisioned (for example, 1000 RUs).
    • 选择“确定” 。Select OK.

    Cassandra API 的屏幕截图,突出显示“添加表”对话框

备注

Cassandra API 的主键用作分区键。For Cassandra API, the primary key is used as the partition key.

使用 .NET SDK 创建Create using .NET SDK

// Create a Cassandra table with a partition/primary key and provision 1000 RU/s throughput.
session.Execute(CREATE TABLE myKeySpace.myTable(
    user_id int PRIMARY KEY,
    firstName text,
    lastName text) WITH cosmosdb_provisioned_throughput=1000);

如果创建集合时遇到超时异常,请执行读取操作来验证是否已成功创建集合。If you encounter timeout exception when creating a collection, do a read operation to validate if the collection was created successfully. 成功完成集合创建操作之前,读取操作将引发异常。The read operation throws an exception until the collection create operation is successful. 有关创建操作所支持的状态代码列表,请参阅 Azure Cosmos DB 的 HTTP 状态代码一文。For the list of status codes supported by the create operation see the HTTP Status Codes for Azure Cosmos DB article.

使用 Azure CLI 创建Create using Azure CLI

使用 Azure CLI 创建 Cassandra 表Create a Cassandra table with Azure CLI. 有关所有 Azure Cosmos DB API 的所有 Azure CLI 示例的列表,请参阅 Azure Cosmos DB 的 Azure CLI 示例For a listing of all Azure CLI samples across all Azure Cosmos DB APIs see, Azure CLI samples for Azure Cosmos DB.

使用 PowerShell 创建Create using PowerShell

使用 PowerShell 创建 Cassandra 表Create a Cassandra table with PowerShell. 有关所有 Azure Cosmos DB API 的所有 PowerShell 示例的列表,请参阅 PowerShell 示例For a listing of all PowerShell samples across all Azure Cosmos DB APIs see, PowerShell Samples

后续步骤Next steps