TIP

💡 Learn more : Azure storage account overview.

Creating your first Azure Storage Table

In case you are new to the Azure Storage, we've reviewed the following options so far:

While we've been working with Azure Storage Blobs and Files, we'll switch this week to taking a look at Azure Storage Tables.

What is Azure Storage Tables? They are a NoSQL key-value store for rapid development using massive semi-structured datasets*

As a refresher, Azure Storage Blobs can store any type of text or binary data, such as a document, media file, or application installer. Blob storage is also referred to as object storage.

So to recap, think of Azure Storage Tables as key-value data set that you can query vs. Azure Storage Blobs which are typically files.

Getting Started

Go ahead and open the Azure Portal and click Create a Resource and select Azure Storage. We'll keep it simple as shown below to get started.

Once complete, go into the resource and look under Services.

Go ahead and click on Tables and you could create a new table through the portal as shown below.

If we did that, then we'd see a table alongwith the URL that it is accessible from.

While this is good and fine, we'd like to create the table dynamically to represent a real-world scenario.

For this example, we'll use C#.

While inside the blade for Azure Storage, look under Settings, then Access Keys and copy the connection string.

Create a C# Console Application using Visual Studio, and use NuGet to pull in references to :

  • WindowsAzure.Storage
  • Microsoft.WindowsAzure.ConfigurationManager

Inside of your Console app, you will see App.config, now add the following section:

  <appSettings>
    <add key="StorageConnection" value="YOUR-CONNECTION-STRING-COPIED-FROM-EARLIER"/>
  </appSettings>
1
2
3

Copy the following code into your Main method:

static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnection"));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("thankfulfor");
table.CreateIfNotExists();
Console.ReadKey();
}
1
2
3
4
5
6
7
8
9

This code will get our connection string from the App.config, create our client and a table named thankfulfor if it doesn't exist. We can go back inside of the portal to see if executed correctly.