0
0
Azurecloud~5 mins

Table storage basics in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Storing data in tables helps organize information in rows and columns without complex databases. Azure Table Storage lets you save lots of simple data with fast access and low cost.
When you want to save user preferences for a web app without a full database.
When you need to log events or telemetry data quickly and cheaply.
When you want to store product catalog information with flexible schema.
When you want to keep session state data for a web application.
When you need a simple key-value store that scales easily.
Config File - azure_table_storage_policy.json
azure_table_storage_policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "TableService.QueryEntities",
        "TableService.AddEntity",
        "TableService.UpdateEntity",
        "TableService.DeleteEntity"
      ],
      "Resource": "https://myaccount.table.core.windows.net/mytable"
    }
  ]
}

This JSON file defines permissions for accessing an Azure Table Storage table named mytable in the storage account myaccount. It allows querying, adding, updating, and deleting entities in the table.

Commands
Create a new Azure Storage account named mystorageaccount in the resource group myResourceGroup located in eastus region. This account will hold the table storage.
Terminal
az storage account create --name mystorageaccount --resource-group myResourceGroup --location eastus --sku Standard_LRS
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount", "location": "eastus", "name": "mystorageaccount", "resourceGroup": "myResourceGroup", "sku": { "name": "Standard_LRS" }, "type": "Microsoft.Storage/storageAccounts" }
--sku - Defines the replication and performance tier of the storage account
--location - Specifies the Azure region where the account is created
Create a new table named mytable inside the mystorageaccount storage account. Tables organize data in rows and columns.
Terminal
az storage table create --name mytable --account-name mystorageaccount
Expected OutputExpected
Created table mytable
--name - Specifies the name of the table to create
--account-name - Specifies which storage account to use
Insert a new entity (row) into the mytable table with PartitionKey 'users' and RowKey '001'. This entity has properties Name and Age.
Terminal
az storage entity insert --table-name mytable --entity PartitionKey=users RowKey=001 Name=Alice Age=30 --account-name mystorageaccount
Expected OutputExpected
No output (command runs silently)
--table-name - Specifies the table to insert the entity into
--entity - Defines the key-value pairs for the entity's properties
Retrieve and display the entity with PartitionKey 'users' and RowKey '001' from the mytable table.
Terminal
az storage entity show --table-name mytable --partition-key users --row-key 001 --account-name mystorageaccount
Expected OutputExpected
{ "PartitionKey": "users", "RowKey": "001", "Timestamp": "2024-06-01T12:00:00Z", "Name": "Alice", "Age": 30 }
--partition-key - Specifies the partition key of the entity to retrieve
--row-key - Specifies the row key of the entity to retrieve
Key Concept

If you remember nothing else from this pattern, remember: Azure Table Storage stores data as simple rows identified by PartitionKey and RowKey for fast and scalable access.

Common Mistakes
Using the same RowKey within a PartitionKey for multiple entities
RowKey must be unique within a PartitionKey; duplicates cause insert failures or overwrite data.
Ensure each entity has a unique combination of PartitionKey and RowKey.
Not specifying the storage account name in commands
Azure CLI commands need the storage account to know where to apply the operation; missing it causes errors.
Always include --account-name with the correct storage account in your commands.
Trying to create a table with invalid characters or names
Table names must follow Azure naming rules; invalid names cause creation to fail.
Use only letters, numbers, and no special characters in table names.
Summary
Create an Azure Storage account to hold your tables.
Create a table inside the storage account to organize your data.
Insert entities with unique PartitionKey and RowKey to store rows.
Retrieve entities by specifying their PartitionKey and RowKey.