Implementing Azure Storage Tables

In this article you will learn how to implement Azure storage tables.

Introduction

Azure Storage is a non-relational (NoSQL) entity storage service on Microsoft Azure. When you create a storage account, it includes the Table service alongside the Blob and Queue services. Table services can be accessed through a URL format. It looks like this,

http://<storage account name>.table.core.windows.net/<table name>.

There are many forms of NoSQL databases:

Key-value stores organize data with a unique key per record and often allow for jagged entries where each row might not have a complete set of values.

Document databases are similar to key-value stores with semi-structured, easy-to-query documents. Usually, information is stored in JavaScript Object Notation (JSON) format.

Columnar stores are used to organize large amounts of distributed information.

Graph databases do not use columns and rows; instead, they use a graph model for storage and queries, usually for large amounts of highly distributed data.

Table storage is a key-value store that uses a partition key to help with scaled out distribution of data and a row key for unique access to a particular entry. Together, these keys are used to uniquely identify a record in the account.

Using basic CRUD Operations

Step 1:
Start Visual Studio 2015 and create a C# Console application,

Console application

Step 2: Go to Azure Management portal and create a new storage account.

new storage account

Step 3: In Visual Studio 2015 under app.config file, add an entry under the Configuration element, replacing the account name and key with your own storage account details,

  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <configuration>  
  3.     <startup>   
  4.         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />  
  5.     </startup>  
  6.     <appSettings>  
  7.     <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=storagefinal1;AccountKey=tFwfGr4sFCtpmf6KjC8WgQpy1vSDFOvavw9ncK2uv5iJni2T7emxrCm/XeDJddB4J1m6eNzG7JBhPeRfdDQlYg==" />  
  8.     </appSettings>  
  9. </configuration>  
Step 4: Now Use NuGet Package Manager to obtain the Microsoft.WindowsAzure.Storage.dll.

code

Step 5: Search for “Azure Storage” and install it.

install

Step 6: Add the following using statements to the top of your Program.cs file,
  1. using Microsoft.WindowsAzure.Storage;  
  2. using Microsoft.WindowsAzure.Storage.Auth;  
  3. using Microsoft.WindowsAzure.Storage.Table;  
  4. using Microsoft.WindowsAzure;  
  5. using System.Configuration;  
also add one reference,

System.Configuration

reference

reference

reference

Step 7: Type the following command to retrieve your connection string in the Main function of Program.cs,
  1. static void Main(string[] args)  
  2. {  
  3.     var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);  
  4. }  
Step 8: Use the following command to create a table if one doesn’t already exist,
  1. static void Main(string[] args)  
  2. {  
  3.     var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);  
  4.   
  5.     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();  
  6.     CloudTable table = tableClient.GetTableReference("customers");  
  7.     table.CreateIfNotExists();  
  8. }  
Now run the Visual Studio Program or Press F5.

Run the “Azure Storage Explorer” tool.

Enter Storage name & key,

Storage name