Create a table in Azure Cosmos DB for Table using .NET

Tables in Azure Cosmos DB for Table are units of management for multiple items. Before you can create or manage items, you must first create a table.

Name a table

In Azure Cosmos DB, a table is analogous to a table in a relational database.

Note

With API for Table accounts, when you create your first table, a default database is automatically created in your Azure Cosmos DB account.

Create a table

To create a table, call one of the following methods:

Create a table asynchronously

The following example creates a table asynchronously:

// New instance of TableClient class referencing the server-side table
TableClient tableClient1 = client.GetTableClient(
    tableName: "adventureworks-1"
);

await tableClient1.CreateAsync();

The TableCient.CreateAsync method will throw an exception if a database with the same name already exists.

Create a table asynchronously if it doesn't already exist

The following example creates a table asynchronously only if it doesn't already exist on the account:

// New instance of TableClient class referencing the server-side table
TableClient tableClient2 = client.GetTableClient(
    tableName: "adventureworks-2"
);

await tableClient2.CreateIfNotExistsAsync();

The TableClient.CreateIfNotExistsAsync method will only create a new table if it doesn't already exist. This method is useful for avoiding errors if you run the same code multiple times.

Next steps

Now that you've created a table, use the next guide to create items.