Create an Azure Storage Table

This document guides you through the process of creating a new table in Azure Table Storage. Azure Table Storage is a NoSQL key-attribute store that allows you to store large amounts of structured, non-relational data. Tables are schemaless, meaning a partition within a table doesn't need to have the same set of properties.

Prerequisites

Methods for Creating a Table

You can create an Azure Storage Table using several methods:

1. Using the Azure Portal

The Azure portal provides a user-friendly graphical interface for managing your storage resources.

  1. Navigate to your storage account in the Azure portal.
  2. In the left-hand navigation pane, under Table Storage, select Tables.
  3. Click the + Table button to create a new table.
  4. Enter a unique name for your table. Table names must be between 3 and 63 characters long and can contain lowercase letters, numbers, and hyphens. Table names must start with a letter.
  5. Click OK to create the table.

2. Using Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources from your terminal.

First, log in to your Azure account:

az login

Then, create a table using the following command:

az storage table create --name MyNewTable --account-name  --account-key 

Replace MyNewTable with your desired table name, and <your-storage-account-name> and <your-storage-account-key> with your actual storage account name and access key.

Note: You can retrieve your storage account name and access keys from the Access keys section of your storage account in the Azure portal.

3. Using Azure SDKs

Azure provides SDKs for various programming languages that allow you to programmatically interact with Azure Storage.

Example using Azure SDK for Python

Ensure you have the Azure Table Storage SDK installed:

pip install azure-data-tables

Here's a Python snippet to create a table:


from azure.data.tables import TableServiceClient

# Replace with your actual connection string
connection_string = "DefaultEndpointsProtocol=https;AccountName=YOUR_ACCOUNT_NAME;AccountKey=YOUR_ACCOUNT_KEY;EndpointSuffix=core.windows.net"
table_name = "MyPythonTable"

try:
    table_service_client = TableServiceClient.from_connection_string(connection_string)
    table_client = table_service_client.create_table(table_name)
    print(f"Table '{table_name}' created successfully.")
except Exception as e:
    print(f"Error creating table: {e}")
            

Table Naming Conventions

When naming your tables, adhere to the following rules:

Best Practices

Tip: For frequently accessed data, consider using partitions effectively to improve query performance.

Once your table is created, you can start inserting, querying, and managing entities within it.