Getting Started With Azure Cosmos DB - Table API

In this article, we will walk through Azure Cosmos DB for Table API. Here is the flow of this write-up.

  • Concepts 
  • Implementation – Creating the Azure Cosmos DB for Table API.
  • Implementation – Query the Data.


  • Azure Cosmos DB is designed to be scalable and performance proof.
  • Previously designed schemas for relational databases are pretty familiar to you.
  • If you are designing for NoSQL/Key value store, in that case, Azure Table service is the best option to choose.
  • The NoSQL data store can enable your solution to scale much faster and that too in lower case.
  • Basically, the solution uses a relational database.
  • Each row of the table represents an entity, every entity has a pair of keys to uniquely identify the row and the timestamp column used to track when the entity was last updated.
  • The best part is that it looks like a table in a relational database with a different key.
  • Schema-less nature of the table service means that a property needs to have the same data type on each entity.
  • To store complex data types, you must use a serialized format such as JSON or XML.
  • As you will see in the demo,  partition key and row key are fundamental to good design. Like every entity stored in the table it must have a unique combination of Partition Key and Row Key.
  • Basically, these values are indexed to create a clustered index that enables much faster look ups.
  • The table is made up of one or more partitions. Partition Key and Row Key is suitable to optimize your solution.
  • The account name, table name, and Partition Key together identify the partition within the same storage service where your table service store the entity.

Implementation – Create the Azure Cosmos DB for table API.

  • Open Azure portal and click on + sign at the left top corner of your screen.

    Azure Cosmos DB
  • Click on Azure Cosmos DB.
  • Fill in the following required details like ID / Name.
  • Choose the API (SQL (Document DB), MongoDB, Gremlin (graph), Table(Key-value)).
  • Let's say we will take Table (key -value pair).
  • Choose subscription and existing resource group or create new as per your requirement.
  • Choose location means which data center you want to store the data in.

    Azure Cosmos DB

  • Click on "Create" button.
  • Once it is deployed, go to - Quick Start and create a default table / click on "Create People Table". You can create your own table also.
  • Once you click on Create ‘People Table' , your default table is created.

    Azure Cosmos DB

  • Click on Data Explorer (Preview) tab at the left side, as shown below.

    Azure Cosmos DB
  • You will see the Entities, Stored Procedures, Triggers etc, as same as your normal SQL Database.
  • Then, click on Entities - Add Entities - Add Table Entities.
  • Give Partition Key and Row key and also add one more Property “City” as shown below.

    Azure Cosmos DB
  • Click on "Add Entity".
  • This will create a record below.
  • Likewise, add one more Entity.

Implementation – Create the Azure Cosmos DB

Azure Cosmos DB

  • Now, we will query the data on the above result set.
  • Click on query builder, select Field Type Operator and type the value as shown in the below picture. Then, click on "Run" button.

    Azure Cosmos DB
  • You will see the following result set.

    Azure Cosmos DB

This is how you can make Table API using Azure Cosmos DB.

Happy Learning.


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now