Creating Storage Account And Table - Understanding Table Storage - Part One

Azure Table Storage is a non-relational database system in the Azure cloud built for massive scale which doesn’t need to share a specific schema. It stores structured NoSQL data in the cloud, providing a key/attribute store and because of its schema-less property, it is easy to adapt data as the needs of your application evolve. Access to Table Storage data is fast and cost-effective for many types of applications and is typically lower in cost than traditional SQL for similar volumes of data. You can store any number of entities in a table, and a storage account may contain any number of tables, up to the capacity limit of the storage account. 
http://<storage account name>.table.core.windows.net/<table name>.
 
Inside tables, we have entities which are a collection of properties and a single entity can have up to 252 properties to store information. Each entity also has three system properties that specify a partition key, a row key, and a timestamp. Entities with the same partition key can be queried more quickly and inserted/updated in operations. An entity's row key is its unique identifier within a partition.
 
Common uses of Table storage include,
  • Storing TBs of structured data capable of serving web-scale applications
  • Storing datasets that don't require complex joins, foreign keys, or stored procedures and can be denormalized for fast access
  • Quickly querying data using a clustered index
  • Accessing data using the OData protocol and LINQ queries with WCF Data Service .NET Libraries

Here in this article first we will create a storage account and have the keys to use it in our application and then a console application, which connects to the storage account and create a table inside it.

Step 1

Log in to your Microsoft Azure portal, click on "Create new resource" and select "Storage account - blob, file, table, queue" from Storage category to create a Storage account and give the necessary details as follows.

  • Name: A Unique Name
  • Deployment: Resource manager
  • Account kind: General purpose (Can’t work with Files, Tables or Queues in case of Blob Storage)
  • Location: Nearest to you
  • Replication: Read-access geo-redundant storage

    • Locally-redundant storage- Three copies within the same data center
    • Zone-redundant storage- Three copies within two data centers of the same region
    • Geo-redundant storage- Three copies in a primary data center and three copies in another data center

  • Performance: Standard (For premium only LRS replication is available as of now)
  • Secure Transfer Required: Disabled
  • Resource group: Create a new as TableStorageRG

 

Azure

Step 2

Once the deployment is succeeded, open the resource and click on Access keys and note a key for a later purpose.
 
Azure
Step 3

Create a new C# Console Application within Visual Studio and name it as TableDemo.
 
Azure

Step 4

Once the project is created, install two NuGet Packages named WindowsAzure.Storage and WindowsAzure.ConfigurationManager to your solution. You can do this by selecting Tools > NuGet Package Manager > Manage NuGet Packages for Solution. In the Browse tab search for WindowsAzure.Storage and WindowsAzure.ConfigurationManager to get the packages complete the installation by reviewing the changes and accepting the license term for both.

Azure
 
Azure

Step 5

Now we have to add the Connection String to the storage account. For that open the App.config file and add following code snippet within the configuration. Replace the [Connection string] with the connection string value you copied in Step 2.

  1. <appSettings>  
  2. <add key="StorageConnection" value="[Connection String]" />  
  3. </appSettings>  
Azure

Step 6

Now, go to the Program.cs Page and add the following code to the Main method. This code will create a connection with the storage account and create a table named images in our blob storage with a Public (Blob) access type.

  1. //Reference to the ConnectionString in the App.Config file  
  2.   
  3. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(  
  4. CloudConfigurationManager.GetSetting("StorageConnection"));  
  5.   
  6. CloudTableClient tableClient = storageAccount.CreateCloudTableClient();  
  7.   
  8. CloudTable table = tableClient.GetTableReference("customers");  
  9. table.CreateIfNotExists();  
  10.   
  11. Console.ReadKey();  

Add the following namespaces also

  1. using Microsoft.Azure;  
  2. using Microsoft.WindowsAzure.Storage;  
  3. using Microsoft.WindowsAzure.Storage.Table;  
Azure

Step 7

Click on Start to run the program and you will see a console window waiting for an input as we given Console.Readkey() at the end of the code.

Azure
Step 8

Go back to your storage account and select Table service from the overview tab and you can see that we now have a customers table there (Refresh if not reflected).
 
Azure
 
Azure


Similar Articles