Azure Table Storage Documentation
Overview of Azure Table Storage
Azure Table Storage is a NoSQL key-attribute store that accepts authenticated calls across the internet and stores non-relational structured data. It's ideal for applications that need a flexible schema and massive scalability. Table Storage is a core component of Azure Cosmos DB, offering a fully managed, globally distributed database service.
Key Concepts
- Tables: Collections of entities. Tables do not enforce a schema, so each entity within a table can have a different set of properties.
- Entities: A set of properties, similar to a row in a database table. An entity can have up to 64 properties (plus system properties).
- Properties: Name-value pairs. Property names are strings, and values can be of various primitive data types (e.g., String, Int32, Int64, Boolean, DateTime, Double, GUID, Binary).
- PartitionKey: Used to group entities within a table. Entities with the same
PartitionKeyare stored together, enabling efficient querying. - RowKey: Uniquely identifies an entity within a partition. The combination of
PartitionKeyandRowKeymust be unique within a table.
When to Use Table Storage
- Storing large amounts of structured, non-relational data.
- Applications that require flexible schemas.
- Need for high throughput and low latency access to data.
- Use cases include user profiles, device information, IoT telemetry, and logs.
Data Modeling Considerations
Effective data modeling in Table Storage involves strategically choosing your PartitionKey and RowKey to optimize query performance. Consider the following:
- Query Patterns: Design keys to support your most frequent query patterns.
- Data Distribution: A good
PartitionKeydistribution prevents hot partitions. - Atomicity: Entities within the same partition can be retrieved or deleted atomically.
Working with Table Storage
Creating a Table
You can create a table using the Azure SDKs for various languages (e.g., .NET, Java, Python, Node.js) or the Azure CLI.
az storage table create --name mynewtable --account-name mystorageaccount --account-key <your_storage_account_key>
Inserting Entities
Entities are inserted into a table as a collection of properties. Each entity requires at least a PartitionKey and a RowKey.
// Example in C#
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("mytable");
MyEntity entity = new MyEntity("partition1", "row1");
entity.Timestamp = DateTime.UtcNow;
entity.Description = "Sample entity";
TableOperation insertOperation = TableOperation.Insert(entity);
table.Execute(insertOperation);
Querying Entities
You can query entities by specifying filter criteria. Queries that leverage the PartitionKey and RowKey are highly efficient.
# Example in Python
table_service = TableService(account_name='mystorageaccount', account_key='<your_storage_account_key>')
entities = table_service.query_entities('mytable', filter="PartitionKey eq 'partition1'")
for entity in entities:
print(entity.RowKey, entity.Description)
Updating and Deleting Entities
Entities can be updated (by replacing existing ones or merging properties) or deleted using similar TableOperation objects.
Pricing and Limits
Refer to the Azure Table Storage pricing page for the latest information on costs and Azure subscription and service limits.
Note
Azure Table Storage is now part of Azure Cosmos DB. You can provision Table API accounts within Cosmos DB for advanced features like global distribution, multi-master writes, and tunable consistency.
Important
Always use HTTPS to communicate with Table Storage. Authentication is handled via Shared Key or Shared Access Signatures (SAS).