.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> Azure >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Azure Part 18: Create Table in Storage Account

Posted By:Jean Paul       Posted Date: November 11, 2011    Points: 200    Category: Azure    URL: http://www.dotnetspark.com  

Create Table in Storage Account

In this article we can explore the table creation in storage account.


As a refresh, I would like to repeat that there are 3 types in Azure Storage

  • Blob
  • Table
  • Queue


The Blob creation was explored in the previous article.  Table creation will be explored here.


Concepts in Table


Following are the key concepts in table.


  • Tables allow structure data storage
  • There can be 0..n tables in a storage account
  • Table store data as a collection of entities
  • Entity have a primary key and properties as key value pair


Note: The table we discuss here is not entirely same as our database table.  The database table will be discussed in SQL Azure.  In Blob Service, the data is stored in containers.  But in Table Service, data is stored in tables.


The steps involved in creating a table are following:


Step 1: Create new project


As always create a new azure project and add a web role into it.  Now add reference to the StorageClient dll file.



Step 2: Define the Entity


Now we need to define the entity with the required properties, create a new class, derive it from TableStorageEntity and define the following properties in it.


Our entity class is  derived from TableStorageEntity because this class takes care of the key properties like PartitionKey, RowKey and necessary attributes.


Step 3: Code Part


Now we can write the code to do the following activities:


  • Do account authentication
  • Create Table client
  • Create table in account
  • Add the new entity to tabl


The following code performs the following:


protected void Page_Load(object sender, EventArgs e)


    StorageCredentialsAccountAndKey accountAndKey = new

      StorageCredentialsAccountAndKey("youraccount", "key");

    CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);


    CloudTableClient client = account.CreateCloudTableClient();



    TableServiceContext tableContext = new




    Contact contact = new Contact();

    contact.PartitionKey = "1";

    contact.RowKey = "1";

    contact.Name = "Contact1";

    contact.Address = "Address1";


    tableContext.AddObject("Contact", contact);




The account name and key can be obtained as explained in the previous article.

Note: We are setting the PartitionKey and RowKey as "1" for demo purposes.  The PartitionKey represents the partition identifier where  the table is stored.  The RowKey should be the unique identifier to the entity. More Info


The classes involved for resembles the ADO.NET Entity Framework classes.


Step 4: Viewing the entity inserted


You can use the Server Explorer to see the new entity inserted as shown below.





In this article we have seen how to define a table and insert entity into it.  

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend