Azure Table Storage: a script to populate new column for existing tables

筅森魡賤 提交于 2019-12-11 17:04:20

问题


I have some tables in my Azure Table Storage and need to deploy a script to populate a new column with empty data for all of them.

I know that some management could be done via PowerShell, but I was unable to find any relevant example or documentation on how to perform this task.

Any help would be appreciated.


回答1:


Regarding the PowerShell script, please refer to the following code:

Install-Module -Name AzTable

$groupName=""
$StorageAccountName = ""
$StorageAccountKey = ""
$vaule=" "
$context = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tables = Get-AzStorageTable -Context $context
Foreach($table in $tables){
    $table = Get-AzTableTable -storageAccountName $StorageAccountName -resourceGroup $groupName="" -TableName
    $entities=Get-AzTableRow -Table $table
    ForEach($e in $entities){
        $entity = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity($e.PartitionKey,$e.RowKey)
        $entity.Properties.Add("Name", $vaue)
        $table.Execute([Microsoft.Azure.Cosmos.Table.TableOperation]::InsertOrMerge($entity))
        Get-AzTableRow -Table $table -PartitionKey $e.PartitionKey -RowKey $e.RowKey
    }

}



回答2:


I have some tables in my Azure Table Storage and need to deploy a script to populate a new column with empty data for all of them.

Basically Azure Table is a key/value pair store so it can't really have columns (key) with no data (value) in it. This is applicable to all supported data types with an exception of String data type where you can store an empty string (it's still not null) as value for a key.

As to how you go about doing it, here're the steps you can follow:

  1. Fetch the entities for which you wish to add a key. To reduce the response payload, you can simply fetch the PartitionKey and RowKey attributes.
  2. For each entity you receive, simply add a new attribute. Please ensure that the attribute's data type is String and set the value of that attribute to empty string ("").
  3. Last you would want to call Merge Entity operation on those entities. This will ensure that only the new attribute will get added. All other existing attributes in that entity will remain unchanged.

Unfortunately I am not too familiar with PowerShell to provide exact syntax. But this should give you enough idea to get going.



来源:https://stackoverflow.com/questions/57460310/azure-table-storage-a-script-to-populate-new-column-for-existing-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!