Storage Tables Entities

Azure Table storage is a NoSQL key-attribute store that accepts authenticated calls. It stores a large amount of structured, non-relational data. You can access your data from anywhere by using authenticated calls to the Azure Table storage REST API. The primary use case is storing flexible datasets for web applications.

What is an Entity?

In Azure Table storage, an entity is a set of properties. You can think of an entity as a row in a table. Each entity has a unique identifier, which is composed of two parts:

  • Partition Key (PartitionKey): A string that logically divides the entities within a table. Entities with the same partition key are stored together. This is crucial for scalability and performance.
  • Row Key (RowKey): A string that uniquely identifies an entity within a partition.

Entity Properties

Each entity can have up to 252 additional properties, in addition to the PartitionKey and RowKey properties. The Timestamp property is automatically managed by the service.

Properties have the following characteristics:

  • Name: The name of the property. Property names are case-insensitive (though the Azure Storage service preserves the case).
  • Type: The data type of the property. Azure Table storage supports several data types, including:
    • String
    • Boolean
    • DateTime
    • Double
    • Guid
    • Int32
    • Int64
    • DateTimeOffset
    • String (for Binary Large Objects - BLOBS)
    • String (for XML)
  • Value: The data stored in the property.

Note: Azure Table storage automatically indexes the PartitionKey and RowKey properties. You can define up to 252 custom indexed properties. Properties not explicitly defined in a request are not indexed.

Entity Structure and Limits

An entity in Azure Table storage has the following structure:

  • PartitionKey (String, required)
  • RowKey (String, required)
  • Timestamp (DateTime, read-only, system-generated)
  • Up to 252 custom properties (various data types)

Each entity can be up to 1 MB in size.

Example Entity

Consider a simple scenario where we store product information. Each entity might represent a specific product variant:

Property Type Value Description
PartitionKey String Electronics Category of the product.
RowKey String SKU12345 Unique SKU for the product variant.
Timestamp DateTime 2023-10-27T10:30:00Z System generated timestamp.
Name String Smart LED TV Product name.
Brand String AwesomeTech Brand of the product.
Price Double 499.99 Price of the product.
InStock Boolean true Availability status.
ReleaseDate DateTime 2023-01-15T00:00:00Z Date the product was released.

Key Concepts for Entities

Atomicity: Operations on a single entity (e.g., insert, update, delete) are atomic. However, Azure Table storage does not support transactions across multiple entities or tables directly. For batch operations, you can use entity group transactions, which group up to 100 entities for insertion, updates, or deletions, provided they share the same partition key.

Data Type Flexibility: The schema-less nature of Azure Table storage allows you to store entities with varying property sets within the same table. This is highly beneficial for evolving applications and diverse data structures.

Tip: Carefully choose your PartitionKey and RowKey. A good partition key strategy is essential for efficient querying and high throughput. Consider common query patterns when designing your keys.

Working with Entities

You can interact with entities using:

  • Azure SDKs (available for various languages like .NET, Java, Python, Node.js)
  • Azure CLI
  • Azure Storage Explorer
  • REST API

Common operations include:

  • Inserting a new entity.
  • Querying entities based on partition and row keys or other properties.
  • Updating existing entities.
  • Deleting entities.
  • Performing batch operations using entity group transactions.

For detailed code examples and API references, please refer to the Azure Table storage documentation and SDKs.