Azure Documentation

Getting Started with Azure Table Storage

Unlock Scalable NoSQL Data with Azure Table Storage

Begin your journey with Azure Table Storage, a cost-effective and highly scalable NoSQL datastore for structured, non-relational data.

What is Azure Table Storage?

Azure Table Storage is a NoSQL key-attribute store that accepts selections from many different data entities. It's designed for storing large amounts of structured, non-relational data. Each table is a collection of entities, and each entity is a collection of properties. Entities do not need to share the same set of properties, which allows for flexible schema design.

Key Concepts

  • Account: You need an Azure Storage account to use Table Storage.
  • Table: A collection of entities. Tables are schemaless.
  • Entity: Represents a set of properties. An entity is analogous to a row in a database. Maximum size of an entity is 1MB.
  • Properties: A name-value pair within an entity. Each property is a name, an OData data type, and a value.
  • PartitionKey: Used to group entities within a table. Entities with the same PartitionKey are stored together, improving query performance.
  • RowKey: Uniquely identifies an entity within a partition. PartitionKey and RowKey together form the primary key of an entity.

Steps to Get Started

1. Create an Azure Storage Account

If you don't already have one, the first step is to create an Azure Storage account. You can do this through the Azure portal, Azure CLI, or Azure PowerShell.

Note: Ensure you select a region that is appropriate for your application's needs.

2. Install Azure Storage SDK

Azure Table Storage can be accessed using various SDKs. Choose the SDK for your preferred programming language:

3. Connect to Your Storage Account

To connect, you'll typically use your storage account's connection string. This string contains your account name and access key.

DefaultEndpointsProtocol=https;AccountName=your_account_name;AccountKey=your_account_key;EndpointSuffix=core.windows.net

4. Create a Table

Once connected, you can create a new table. Tables are schemaless, so you don't define columns upfront. You can use the SDK for this:

// Example using .NET SDK
                TableClient tableClient = new TableClient(connectionString, "MyNewTable");
                tableClient.CreateIfNotExists();

5. Insert an Entity

Entities are represented as objects. You need to define the PartitionKey and RowKey for each entity.

# Example using Python SDK
                from azure.data.tables import TableClient, UpdateMode

                table_client = TableClient.from_connection_string(connection_string, "MyNewTable")

                entity = {
                    "PartitionKey": "Customers",
                    "RowKey": "12345",
                    "Name": "John Doe",
                    "Email": "john.doe@example.com",
                    "Membership": "Premium"
                }

                table_client.upsert_entity(entity, mode=UpdateMode.MERGE)

6. Query Entities

You can query entities based on partition and row keys, or use OData filters for more complex queries.

/* Example using JavaScript SDK
                const { TableServiceClient } = require("@azure/data-tables");

                const serviceClient = TableServiceClient.fromConnectionString(connectionString);
                const tableClient = serviceClient.getTableClient("MyNewTable");

                // Query for a specific entity
                const entity = await tableClient.getEntity("Customers", "12345");
                console.log(entity);

                // Query with a filter
                const entities = tableClient.listEntities({
                    filter: "PartitionKey eq 'Customers' and Membership eq 'Premium'"
                });
                for await (const entity of entities) {
                    console.log(entity);
                } */

Tip: Efficiently querying data often involves careful design of PartitionKey and RowKey to leverage partition and row key ranges.

Next Steps