Azure Storage Tables API

The Azure Storage Tables API enables you to store and query large amounts of structured, non-relational data. It's a NoSQL key-attribute store. Data in a table is a collection of entities, and each entity is a collection of properties. Tables do not enforce a schema, so different entities within the same table can have different sets of properties.

Introduction

Azure Table Storage is a service that stores NoSQL key-attribute data. It's a good choice for storing flexible datasets like user data for web applications, address books, device information, or any other type of metadata that your service requires.

Key concepts:

Core Operations

The Tables API supports a set of REST operations to manage tables and entities.

Table Operations

These operations allow you to manage tables within your storage account.

Operation HTTP Method Description URI
Create Table POST Creates a new table. /Tables
List Tables GET Lists all tables in the storage account. /Tables
Delete Table DELETE Deletes a table. /Tables('TableName')
Query Tables GET Queries for tables based on a filter. /Tables?$filter=TableName eq 'MyTable'

Entity Operations

These operations allow you to manage entities within a specific table.

Operation HTTP Method Description URI
Insert Entity POST Inserts a new entity into a table. /Entities('TableName')
Update Entity PUT Updates an existing entity. /Entities('TableName')(PartitionKey='PK',RowKey='RK')
Merge Entity MERGE Merges properties of an existing entity. /Entities('TableName')(PartitionKey='PK',RowKey='RK')
Delete Entity DELETE Deletes an entity. /Entities('TableName')(PartitionKey='PK',RowKey='RK')
Query Entities GET Queries for entities within a table. /Entities('TableName')

Entities and Properties

An entity is defined by its properties. The PartitionKey and RowKey are mandatory and form the entity's primary key. Properties can be of various primitive types.

Example Entity Structure:

{
  "PartitionKey": "Customers",
  "RowKey": "ABC123",
  "Name": "John Doe",
  "Email": "john.doe@example.com",
  "Age": 30,
  "IsActive": true,
  "RegistrationDate": "2023-10-27T10:00:00Z"
}
            

Querying Entities

You can query entities using OData syntax. Filters can be applied to select specific entities based on property values.

Example Query: Retrieve all active customers in the 'Customers' partition.


GET /Tables('Customers')/Entities?$filter=PartitionKey eq 'Customers' and IsActive eq true
Accept: application/json
DataServiceVersion: 3.0;NetTr:1
MaxDataServiceVersion: 3.0;NetTr:1
        

Supported Query Operators:

Authentication

Access to Azure Storage Tables is secured using Shared Key authorization or Shared Access Signatures (SAS). You can also integrate with Azure Active Directory for token-based authentication.

Note: Always use the latest available version of the Storage REST API for security best practices and new features.

Batch Operations

Batch operations allow you to send multiple entity operations (insert, update, delete) in a single HTTP request, improving efficiency.

A batch request uses the application/http content type and includes a batch boundary. Each operation within the batch is an independent HTTP request.

Transactions

Azure Table Storage supports entity group transactions. A transaction involves a set of entities that must all succeed or all fail. All entities in a transaction must share the same PartitionKey.