Azure Documentation

Programming Azure Table Storage

Azure Table Storage is a NoSQL key-attribute store that you can use to store large amounts of unstructured and semi-structured data. It's a cost-effective and scalable solution for many application needs. This guide covers the fundamentals of programming with Azure Table Storage.

Core Concepts

Entities: The basic unit of data in Table Storage. An entity is a set of name-value pairs. Each entity has a PartitionKey and a RowKey, which together uniquely identify it.

  • PartitionKey: Groups entities together. Queries that target a specific PartitionKey are very efficient.
  • RowKey: Uniquely identifies an entity within a PartitionKey.

Tables: Collections of entities. A table does not enforce a schema, meaning different entities within the same table can have different properties.

Operations

You can perform the following common operations on Azure Table Storage:

  • Create Table: Creates a new table.
  • Insert Entity: Adds a new entity to a table.
  • Query Entities: Retrieves entities from a table. Queries can be filtered by PartitionKey, RowKey, and other properties.
  • Update Entity: Modifies an existing entity.
  • Delete Entity: Removes an entity from a table.
  • Delete Table: Deletes an entire table.

Getting Started with SDKs

Azure provides SDKs for various programming languages to interact with Table Storage:

Example: Inserting an Entity (Conceptual)

Here's a conceptual example of how you might insert an entity using a client library:

// Assuming 'tableClient' is an initialized TableServiceClient

// Define entity properties
var customer = new Dictionary
{
    { "PartitionKey", "Customers" },
    { "RowKey", "123" },
    { "Name", "Alice Smith" },
    { "Email", "alice.smith@example.com" },
    { "OrderCount", 5 }
};

// Insert the entity into the 'Customers' table
await tableClient.UpsertEntityAsync(new TableEntity(customer), TableUpdateMode.Replace);

Example: Querying Entities (Conceptual)

This example shows how to query entities with a specific PartitionKey:

# Assuming 'table_client' is an initialized TableServiceClient

# Query entities with PartitionKey 'Customers'
query = table_client.query_entities(
    filter_expression="PartitionKey eq 'Customers'"
)

for entity in query:
    print(f"Name: {entity.get('Name')}, Email: {entity.get('Email')}")

Performance Considerations

  • Design your PartitionKeys for efficient querying. Distribute your data evenly across partitions to avoid hot partitions.
  • Use appropriate query filters to retrieve only the data you need.
  • Consider batch operations for inserting or updating multiple entities.
Note: Azure Table Storage is now part of Azure Cosmos DB. While you can still use the original Table Storage APIs, consider using Azure Cosmos DB for Table API for enhanced features, throughput, and global distribution capabilities.

Further Reading