What Is Azure Table Storage

Introduction

 
Azure Table Storage in a layman’s language is a service that helps in storing non-relational structured data which is also known as the NoSQL data. This data can be used in storage and data operations on structured or semi-structured data.
 
Know more about table storage, click on below link

Why Azure Table Storage?

 
Azure Table Storage service is a schema-less where data is stored in tables as a collection of entities which are easier to adapt your data as the application and their need evolves. These table storage data is fast and cost-effective for many different types of applications. Since there are more than one entity in a table, that means one can store multiple entities in a table having different properties. The cost of this is lower than the traditional SQL for similar volumes of data.
 
Table storage can be used to store flexible datasets like user data for web applications, address books, device information, or other types of metadata that are required by your service. 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.
 
Each entity can have up to 252 properties and 3 reserved mandatory properties they are,
  • PartitonKey
  • RowKey
  • Timestamp

What do we mean by the properties mentioned above?

 
Properties are the unique and case sensitive just like table name and should be reviewed while creating a table. Let me explain this to you by using a example of a ‘toy’. Let us consider toy as an entity, then its properties would be barcode, company’s name, etc. Similarly like this there are 252 custom properties and 3 system properties. These 3 system properties are PartitionKey, RowKey and Timestamp (as mentioned earlier).
 
Note
Timestamp is system generated but you will have to specify the PartitionKey and RowKey while inserting data into the table.
 

How to Create Table Storage Using Azure Portal

 
Before creating the table storage you must have azure subscription, resource group and storage account. To check how to create azure subscription please click on below link,
Below are the simple step to create table storage in azure
  1. Login on azure portal portal.azure.com and go to home page.

    What Is Azure Table Storage

  2. Go to storage account and click on it.

    What Is Azure Table Storage

    Here you will find your storage accounts that you have already created. Select the one and click on it.

    What Is Azure Table Storage
  1. after open the storage account you will find different type of storage services like Blob service, queue service, file service and table service. I have already explained Blob and queue services in my previous article.
Now go to Table service and click on 'Tables'.

What Is Azure Table Storage
  1. After click on 'Tables' further click on '+Table' to click a new table. give the name of table and click on 'Ok'.

    What Is Azure Table Storage
     

Steps on Managing Tables Using PowerShell

 
Step 1
 
Download and install Windows PowerShell on the system.
 
Step 2
 
Choose ‘Pin to taskbar’ by right-clicking on the ‘Windows PowerShell’. This will pin it to the taskbar of your computer. 
 
Step 3
 
‘Run ISE as Administrator’ is to be choosen on this step.
 

Step for creating a Table

 
Step 1
 
Copy these commands given below and paste them into your screen. The highlighted text is to be replaced with your account.
 
Step 2
 
Now login into your account.
  1. $StorageAccountName = "csharpcorner"   
  2. $StorageAccountKey = *******************************  
  3. $Ctx = New-AzureStorageContext $StorageAccountName - StorageAccountKey   
  4. $StorageAccountKey  
Step 3
 
Go on creating a new table.
  1. $tabName = "Employee"   
  2. New-AzureStorageTable –Name $tabName –Context $Ctx   
Data can be retrieved, deleted and inserted into the table using preset commands in PowerShell.
 
Retrieve Table
  1. $tabName = "Employee"   
  2. Get-AzureStorageTable –Name $tabName –Context $Ctx  
Delete Table
  1. $tabName = "Employee"  
  2. Remove-AzureStorageTable –Name $tabName –Context $Ctx  
Insert rows into Table
  1. function Add-Entity() {   
  2.    [CmdletBinding()]   
  3.       
  4.    param(   
  5.       $table,   
  6.       [String]$partitionKey,   
  7.       [String]$rowKey,   
  8.       [String]$name,   
  9.       [Int]$id,   
  10.       [String]$address,   
  11.       [String]$dpt   
  12.    )    
  13.      
  14.    $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity   
  15.       -ArgumentList $partitionKey, $rowKey   
  16.           
  17.    $entity.Properties.Add("Name", $name)   
  18.    $entity.Properties.Add("ID", $id)   
  19.    $entity.Properties.Add("Address", $address)   
  20.    $entity.Properties.Add("Dpt", $dpt)   
  21.      
  22.      
  23.    $result = $table.CloudTable.Execute(  
  24.       [Microsoft.WindowsAzure.Storage.Table.TableOperation]  
  25.       ::Insert($entity))   
  26. }  
  27.     
  28. $StorageAccountName = "csharpcorner"   
  29. $StorageAccountKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName   
  30. $Ctx = New-AzureStorageContext $StorageAccountName - StorageAccountKey   
  31.    $StorageAccountKey.Primary    
  32.   
  33. $TableName = "Employee"  
  34.     
  35. $table = Get-AzureStorageTable –Name $TableName -Context $Ctx -ErrorAction Ignore   
Retrieve Table Data
  1. $StorageAccountName = "csharpcorner"   
  2. $StorageAccountKey = Get-AzureStorageKey - StorageAccountName $StorageAccountName   
  3. $Ctx = New-AzureStorageContext – StorageAccountName $StorageAccountName -  
  4.    StorageAccountKey $StorageAccountKey.Primary;   
  5.   
  6. $TableName = "Employee"  
  7.    
  8. #Get a reference to a table.   
  9. $table = Get-AzureStorageTable –Name $TableName -Context $Ctx    
  10.  
  11. #Create a table query.   
  12. $query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery  
  13.  
  14. #Define columns to select.   
  15. $list = New-Object System.Collections.Generic.List[string]   
  16. $list.Add("RowKey")   
  17. $list.Add("ID")   
  18. $list.Add("Name")   
  19. $list.Add("Address")   
  20. $list.Add("Dpt")  
  21.    
  22. #Set query details.   
  23. $query.FilterString = "ID gt 0"   
  24. $query.SelectColumns = $list   
  25. $query.TakeCount = 20  
  26.   
  27. #Execute the query.   
  28. $entities = $table.CloudTable.ExecuteQuery($query)  
  29.  
  30. #Display entity properties with the table format.   
  31.   
  32. $entities  | Format-Table PartitionKey, RowKey, @{ Label = "Name";   
  33. Expression={$_.Properties["Name"].StringValue}}, @{ Label = "ID";   
  34. Expression={$_.Properties[“ID”].Int32Value}}, @{ Label = "Address";   
  35. Expression={$_.Properties[“Address”].StringValue}}, @{ Label = "Dpt";   
  36. Expression={$_.Properties[“Dpt”].StringValue}} -AutoSize   
Delete Rows from Table
  1. $StorageAccountName = "csharpcorner"   
  2.    
  3. $StorageAccountKey = Get-AzureStorageKey - StorageAccountName $StorageAccountName   
  4. $Ctx = New-AzureStorageContext – StorageAccountName $StorageAccountName -   
  5.    StorageAccountKey $StorageAccountKey.Primary    
  6.  
  7. #Retrieve the table.   
  8. $TableName = "Csharpcorner"   
  9. $table = Get-AzureStorageTable -Name $TableName -Context $Ctx -ErrorAction   
  10. Ignore   
  11.  
  12. #If the table exists, start deleting its entities.   
  13. if ($table -ne $null) {   
  14.    #Together the PartitionKey and RowKey uniquely identify every     
  15.    #entity within a table.  
  16.       
  17.    $tableResult = $table.CloudTable.Execute(  
  18.       [Microsoft.WindowsAzure.Storage.Table.TableOperation]   
  19.       ::Retrieve(“Partition1”, "Row1"))   
  20.           
  21.    $entity = $tableResult.Result;  
  22.       
  23.    if ($entity -ne $null) {  
  24.       $table.CloudTable.Execute(  
  25.          [Microsoft.WindowsAzure.Storage.Table.TableOperation]   
  26.          ::Delete($entity))   
  27.    }   
  28. }  
This script will delete the first row from the table, as Partition1 and Row1 are clearly specified in the script. After you are done with deleting the row, check for the result by running the script for retrieving rows. The result you will be getting is that the first row is deleted.
 
Note
Please make sure before running these commands please that the account name is replaced with your account name and accountkey with your account key.
 

Steps to Manage Table using Azure Storage Explorer

 
Step 1
 
Log in to your Azure account.
 
Step 2
 
Now, look for your storage account.
 
Step 3
 
Click on the link for ‘Storage explorer’.
 
Step 4
 
Choose ‘Azure Storage Explorer for Windows’ from the list.
 
Note
Azure Storage Explorer for Windows is a free tool that can be downloaded and installed on the computer.
 
Step 5
 
Click on the ‘Add Account’ button at the top while running this program on your computer.
 
Step 6
 
Enter ‘Storage Account Name’ and ‘Storage account Key’ and click ‘Test Access.
 
Step 7
 
Existing ‘Tables' of the storage are in the left panel under tables. Click on the row to get the access.
 

Steps for Creating a Table

 
Step 1
 
Click on ‘New’ and enter the name of the table.
 
Insert Row into Table
 
Step 1
 
Click on ‘+Add' to add a field.
 
Step 2
 
Enter Field Name and value by click on add property.
 
Step 3
 
From the dropdown menu, select the data type and enter the field value.
 
Step 4
 
Click on insert
 
What Is Azure Table Storage 
 
Azure Storage Explorer is a very easy interface developer as compared to writing lengthy scripts in Windows PowerShell. On, Azure Storage Explorer it is easy to upload, create, delete and download and manage the tables.
 

Summary

 
Hope you understand all the methods of creating table storage from the portal, using PowerShell and Azure storage explorer. Try these simple steps and let me know if any queries. You can check more articles on azure table storage here,
Thanks for reading. Have a good day.