Azure Table Storage is a NoSQL key-attribute store that accepts authenticated calls using HTTP or HTTPS. It’s a service that stores large amounts of structured, non-relational data. Table storage is efficient and can hold a vast quantity of data. A table in Table Storage is a collection of entities. Each entity is a set of properties, similar to a row in a database.
Key Concepts
Entities
An entity is a record, akin to a row in a relational database. An entity can have any number of properties, up to 1 MB in total for all properties.
Each entity is uniquely identified by two key properties:
- PartitionKey: This property is a string value that groups entities. Entities with the same
PartitionKeyare co-located on the storage server. This helps optimize queries that target entities within a specific partition. - RowKey: This property is a string value that uniquely identifies an entity within a partition. Combined with
PartitionKey, it forms the entity's unique identifier (PartitionKey+RowKey).
Properties
A property is a name-value pair within an entity. Each property consists of a name (a string) and a value (one of the supported data types).
Property names are strings and are case-insensitive. An entity can have up to 252 properties, excluding the PartitionKey, RowKey, and Timestamp properties.
Supported data types for property values include:
- String
- Int32
- Int64
- Boolean
- DateTime
- Double
- GUID
- Binary (Byte array)
- String (Edm.String)
- Int32 (Edm.Int32)
- Int64 (Edm.Int64)
- Boolean (Edm.Boolean)
- DateTime (Edm.DateTime)
- Double (Edm.Double)
- GUID (Edm.Guid)
- Binary (Edm.Binary)
- Single precision floating point (Edm.Single)
- Decimal (Edm.Decimal)
- DateTimeOffset (Edm.DateTimeOffset)
Special Properties
PartitionKey: String, required.RowKey: String, required.Timestamp: DateTime, automatically managed by Azure Storage.
An entity can have up to 252 custom properties in addition to these three special properties.
Table Structure
A table is a collection of entities. All entities within a table must have the same set of properties, but individual properties can be null or empty. Tables do not enforce a fixed schema.
Example Data Model
Consider a table storing product inventory:
| PartitionKey | RowKey | Timestamp | ProductName | Category | Quantity | Price | IsAvailable |
|---|---|---|---|---|---|---|---|
| Electronics | P001 | 2023-10-26T10:00:00Z | Laptop Pro X | Computers | 50 | 1200.50 | true |
| Electronics | P002 | 2023-10-26T10:05:00Z | Wireless Mouse | Accessories | 200 | 25.99 | true |
| Apparel | A101 | 2023-10-26T11:15:00Z | Cotton T-Shirt | Tops | 150 | 19.95 | true |
| Apparel | A102 | 2023-10-26T11:20:00Z | Denim Jeans | Bottoms | 75 | 49.99 | false |
In this example:
PartitionKeycould represent broad product categories like "Electronics" or "Apparel".RowKeycould be a unique product ID like "P001" or "A101".Timestampis managed by Azure Storage.- Custom properties include
ProductName,Category,Quantity,Price, andIsAvailable.
Querying and Performance
The combination of PartitionKey and RowKey is the entity's unique identifier. Queries that specify both the PartitionKey and RowKey (point queries) are the most efficient, retrieving a single entity very quickly.
Queries targeting a single PartitionKey are also highly performant as they only scan entities within that partition. Queries that span multiple partitions or do not specify a PartitionKey (e.g., a table scan) can be less efficient and more costly, especially for large tables.
PartitionKey is crucial for performance. Group related entities that are frequently queried together into the same partition.
Data Type Considerations
While Table Storage offers flexibility, using appropriate data types for your properties can impact query performance and storage costs. For example, storing dates as DateTime objects is more efficient for date-based queries than storing them as strings.
When inserting or updating entities, you can specify the OData metadata to indicate the data type of a property if it's not implicitly inferable.
Next Steps
Now that you understand the data model, you can learn how to interact with Azure Table Storage using: