Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update RowKey or PartitionKey in Azure Table Storage

Can i update RowKey or PartitionKey properties of entity in Azure Table Storage?

I thought yes or maybe just PartitionKey but now i am trying to do that(try to change RowKey or PartitionKey) and get error:

The remote server returned an error: (404) Not Found.
Description: An unhandled exception occurred during the execution of the current 
             web request. Please review the stack trace for more information about 
             the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error:
                  (404) Not Found.

Source Error:

Line 143:
Line 144:                var updateOperation = TableOperation.Replace(entity);
Line 145:                _table.Execute(updateOperation);
Line 146:            }
Line 147:        }

My Code to update entity(short version):

var query = new TableQuery<CalculatorAccessTokenEntity>()
                .Where(TableQuery.GenerateFilterCondition("AccessUrl", 
                                                           QueryComparisons.Equal, url));

var newToken = GetUniqueKey(5);//get some random string of length 5
entity.PartitionKey = newToken;

// Try to use Merge here also but unsuccessful
var updateOperation = TableOperation.Replace(entity);    _table.Execute(updateOperation);
like image 798
user3770925 Avatar asked Jul 28 '14 15:07

user3770925


People also ask

What is PartitionKey and RowKey in Azure table?

The row key is a unique identifier for an entity within a given partition. Together the PartitionKey and RowKey uniquely identify every entity within a table. The row key is a string value that may be up to 1 KiB in size. You must include the RowKey property in every insert, update, and delete operation.

How do I update my Azure table storage?

You can construct the Update Entity request as follows. HTTPS is recommended. Replace myaccount with the name of your storage account, and mytable with the name of your table. Replace myPartitionKey and myRowKey with the name of the partition key and row key that identify the entity to be updated.

How should you choose a good partition key for a table storage implementation?

How should you choose a good partition key for a Table storage implementation? (Choose all that apply.) They should always be unique, like a primary key in a SQL table. You should always use the same partition key for all records. Think about how you're likely to update the data using batch transactions.

Is Azure table storage being deprecated?

Azure table storage is deprecated, but still in use by some organizations. Many organizations are still using Azure table storage because it is easy to use, and it has a lot of features. However, as Azure table storage becomes more difficult to use, organizations may want to look into alternatives, such as Cosmos DB.


1 Answers

No, you can't update an entity's PartitionKey or RowKey. What you would need to do is perform 2 operations: first delete the entity with existing PartitionKey/RowKey and then insert new entity with new PartitionKey/RowKey.

like image 167
Gaurav Mantri Avatar answered Oct 17 '22 02:10

Gaurav Mantri