Timestamp property on Windows Azure Table entity. 16 Jan 2013 Azure, Azure Storage, Best practice or not?, Cloud, Lessons learned Every entity in Azure Table Storage has PartitionKey, RowKey and Timestamp property. PartitionKey gives the “bucket” where the entity will be stored (entities in one partition can be on more machines, though). Nov 14, 2016 How to retrieve latest record using RowKey or Timestamp in Azure Table storage. Ask Question 10. Tricky part is RowKey is string which is having value like Mon Nov 14 12. I tried query using Timestamp like. Var lowerlimit = DateTime.UtcNow; // its should be nearer to table timestamp data.
-->Tip
The content in this article applies to Azure Table storage. However, there is now a premium offering for table storage, the Azure Cosmos DB Table API that offers throughput-optimized tables, global distribution, and automatic secondary indexes. To learn more and try out the premium experience, please check out Azure Cosmos DB Table API. This article's programming language is not yet supported in the premium offering, but will be added in the future.
Azure Table storage is a NoSQL datastore that you can use to store and query huge sets of structured, non-relational data. The main components of the service are tables, entities, and properties. A table is a collection of entities. An entity is a set of properties. Each entity can have up to 252 properties, which are all name-value pairs. This article assumes that you are already familiar with the Azure Table Storage Service concepts. For detailed information, see Understanding the Table Service Data Model and Get started with Azure Table storage using .NET.
This how-to article covers common Azure Table storage operations. You learn how to:
- Create a table
- Retrieve a table
- Add table entities
- Query a table
- Delete table entities
- Delete a table
This how-to article shows you how to create a new Azure Storage account in a new resource group so you can easily remove it when you're done. If you'd rather use an existing Storage account, you can do that instead.
The examples require Az PowerShell modules
Az.Storage (1.1.0 or greater)
and Az.Resources (1.2.0 or greater)
. In a PowerShell window, run Get-Module -ListAvailable Az*
to find the version. If nothing is displayed, or you need to upgrade, see Install Azure PowerShell module.Important
Using this Azure feature from PowerShell requires that you have the
Az
module installed. The current version of AzTable
is not compatible with the older AzureRM module.Follow the latest install instructions for installing Az module if needed.After Azure PowerShell is installed or updated, you must install module AzTable, which has the commands for managing the entities. To install this module, run PowerShell as an administrator and use the Install-Module command.
Important
For module name compatibility reasons we are still publishing this same module under the old name
AzureRmStorageTables
in PowerShell Gallery. This document will reference the new name only.Sign in to Azure
Sign in to your Azure subscription with the
Add-AzAccount
command and follow the on-screen directions.Retrieve list of locations
If you don't know which location you want to use, you can list the available locations. After the list is displayed, find the one you want to use. These examples use eastus. Store this value in the variable location for future use.
Create resource group
Create a resource group with the New-AzResourceGroup command.
An Azure resource group is a logical container into which Azure resources are deployed and managed. Store the resource group name in a variable for future use. In this example, a resource group named pshtablesrg is created in the eastus region.
Create storage account
Create a standard general-purpose storage account with locally redundant storage (LRS) using New-AzStorageAccount. Be sure to specify a unique storage account name. Next, get the context that represents the storage account. When acting on a storage account, you can reference the context instead of repeatedly providing your credentials.
Create a new table
To create a table, use the New-AzStorageTable cmdlet. In this example, the table is called
pshtesttable
.Retrieve a list of tables in the storage account
Retrieve a list of tables in the storage account using Get-AzStorageTable.
Retrieve a reference to a specific table
To perform operations on a table, you need a reference to the specific table. Get a reference using Get-AzStorageTable.
Reference CloudTable property of a specific table
Important
Usage of CloudTable is mandatory when working with AzTable PowerShell module. Call the Get-AzTableTable command to get the reference to this object. This command also creates the table if it does not already exist.
To perform operations on a table using AzTable, you need a reference to CloudTable property of a specific table.
Managing table entities
Now that you have a table, let's look at how to manage entities, or rows, in the table.
Entities can have up to 255 properties, including three system properties: PartitionKey, RowKey, and Timestamp. You're responsible for inserting and updating the values of PartitionKey and RowKey. The server manages the value of Timestamp, which can't be modified. Together the PartitionKey and RowKey uniquely identify every entity within a table.
- PartitionKey: Determines the partition that the entity is stored in.
- RowKey: Uniquely identifies the entity within the partition.
You may define up to 252 custom properties for an entity.
Add table entities
Add entities to a table using Add-AzTableRow. These examples use partition keys with values
partition1
and partition2
, and row keys equal to state abbreviations. The properties in each entity are username
and userid
.Query the table entities
You can query the entities in a table by using the Get-AzTableRow command.
Note
The cmdlets Get-AzureStorageTableRowAll, Get-AzureStorageTableRowByPartitionKey, Get-AzureStorageTableRowByColumnName, and Get-AzureStorageTableRowByCustomFilter are deprecated and will be removed in a future version update.
Retrieve all entities
This command yields results similar to the following table:
userid | username | partition | rowkey |
---|---|---|---|
1 | Chris | partition1 | CA |
3 | Christine | partition1 | WA |
2 | Jessie | partition2 | NM |
4 | Steven | partition2 | TX |
Retrieve entities for a specific partition
The results look similar to the following table:
userid | username | partition | rowkey |
---|---|---|---|
1 | Chris | partition1 | CA |
3 | Christine | partition1 | WA |
Retrieve entities for a specific value in a specific column
This query retrieves one record.
field | value |
---|---|
userid | 1 |
username | Chris |
PartitionKey | partition1 |
RowKey | CA |
Retrieve entities using a custom filter
This query retrieves one record.
field | value |
---|---|
userid | 1 |
username | Chris |
PartitionKey | partition1 |
RowKey | CA |
Updating entities
There are three steps for updating entities. First, retrieve the entity to change. Second, make the change. Third, commit the change using Update-AzTableRow.
Update the entity with username = 'Jessie' to have username = 'Jessie2'. This example also shows another way to create a custom filter using .NET types.
The results show the Jessie2 record.
field | value |
---|---|
userid | 2 |
username | Jessie2 |
PartitionKey | partition2 |
RowKey | NM |
Deleting table entities
You can delete one entity or all entities in the table.
Deleting one entity
To delete a single entity, get a reference to that entity and pipe it into Remove-AzTableRow.
Delete all entities in the table
To delete all entities in the table, you retrieve them and pipe the results into the remove cmdlet.
Delete a table
To delete a table, use Remove-AzStorageTable. This cmdlet removes the table, including all of its data.
Clean up resources
If you created a new resource group and storage account at the beginning of this how-to, you can remove all of the assets you have created in this exercise by removing the resource group. This command deletes all resources contained within the group as well as the resource group itself.
Next steps
In this how-to article, you learned about common Azure Table storage operations with PowerShell, including how to:
- Create a table
- Retrieve a table
- Add table entities
- Query a table
- Delete table entities
- Delete a table
For more information, see the following articles
- Microsoft Azure Storage Explorer is a free, standalone app from Microsoft that enables you to work visually with Azure Storage data on Windows, macOS, and Linux.