Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Azure Table Storage Tutorial

Introduction

Azure Table Storage is a service that stores structured NoSQL data in the cloud, providing a key/attribute store with a schema-less design. This makes it ideal for applications that need to store amounts of data that can be queried and need to handle high read and write volumes. In this tutorial, we will guide you through setting up and using Azure Table Storage from start to finish.

Prerequisites

Before you begin, ensure you have the following:

  • An active Azure subscription
  • Azure Storage account
  • Basic knowledge of Azure Portal and command-line interfaces

Creating an Azure Storage Account

To use Azure Table Storage, you need to create an Azure Storage account. Follow these steps:

  1. Log in to the Azure Portal.
  2. Click on Create a resource.
  3. Search for Storage account and select it.
  4. Click Create.
  5. Fill in the required details such as subscription, resource group, and storage account name.
  6. Choose the appropriate performance and replication options.
  7. Review the settings and click Create.

Once the storage account is created, you can manage it from the Azure Portal.

Creating a Table in Azure Table Storage

To create a table in your Azure Table Storage account, you can use the Azure Portal, Azure CLI, or Azure Storage Explorer. Here, we will use Azure CLI.

Open your terminal and execute the following command:

az storage table create --name MyTable --account-name YourStorageAccountName --account-key YourAccountKey

This command creates a table named "MyTable" in your specified storage account.

Inserting Data into the Table

To insert data into your table, you can use various methods. Here, we'll use Azure CLI.

Execute the following command to insert an entity:

az storage entity insert --account-name YourStorageAccountName --account-key YourAccountKey --table-name MyTable --entity PartitionKey=partition1 RowKey=row1 Name=John Age=30

This command inserts an entity with the specified properties into the "MyTable" table.

Querying Data from the Table

To retrieve data from your table, you can use Azure CLI. Here is an example:

Execute the following command to query entities:

az storage entity query --account-name YourStorageAccountName --account-key YourAccountKey --table-name MyTable --filter "PartitionKey eq 'partition1'"

[ { "PartitionKey": "partition1", "RowKey": "row1", "Name": "John", "Age": 30 } ]

This command queries entities where the PartitionKey is "partition1".

Updating Data in the Table

To update data in your table, you can use Azure CLI. Here's how:

Execute the following command to update an entity:

az storage entity merge --account-name YourStorageAccountName --account-key YourAccountKey --table-name MyTable --entity PartitionKey=partition1 RowKey=row1 Age=35

This command updates the Age property of the entity with the specified PartitionKey and RowKey.

Deleting Data from the Table

To delete data from your table, you can use Azure CLI. Follow this example:

Execute the following command to delete an entity:

az storage entity delete --account-name YourStorageAccountName --account-key YourAccountKey --table-name MyTable --partition-key partition1 --row-key row1

This command deletes the entity with the specified PartitionKey and RowKey from the table.

Conclusion

In this tutorial, we covered the basics of Azure Table Storage, including creating a storage account, creating a table, inserting, querying, updating, and deleting data. Azure Table Storage is a powerful service for handling large amounts of structured data, offering high availability and scalability. With this knowledge, you can now start integrating Azure Table Storage into your applications.