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>.
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:
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.
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
Once the deployment is succeeded, open the resource and click on Access keys and note a key for a later purpose.
Create a new C# Console Application within Visual Studio and name it as TableDemo.
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.
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.
- <add key="StorageConnection" value="[Connection String]" />
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.
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
- CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
- CloudTable table = tableClient.GetTableReference("customers");
Add the following namespaces also
- using Microsoft.Azure;
- using Microsoft.WindowsAzure.Storage;
- using Microsoft.WindowsAzure.Storage.Table;
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.
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).