In this article we can explore the table creation in storage
As a refresh, I would like to repeat that there are 3 types
in Azure Storage
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.
allow structure data storage
can be 0..n tables in a storage account
store data as a collection of entities
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
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
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:
table in account
the new entity to tabl
The following code performs the following:
protected void Page_Load(object sender, EventArgs e)
accountAndKey = new
CloudStorageAccount account =
new CloudStorageAccount(accountAndKey, true);
CloudTableClient client =
tableContext = new
Contact contact = new Contact();
contact.PartitionKey = "1";
contact.RowKey = "1";
contact.Name = "Contact1";
contact.Address = "Address1";
The account name and key can be obtained as explained in the
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
The classes involved for resembles the ADO.NET Entity
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.