This guide demonstrates how to delete a specific entity from an Azure Storage table using various SDKs and REST API.
You can delete an entity using the az storage entity delete command.
az storage entity delete --table-name MyTable \
--partition-key PartitionKey1 \
--row-key RowKey1 \
--account-name mystorageaccount \
--account-key 'YOUR_STORAGE_ACCOUNT_KEY'
Replace MyTable, PartitionKey1, RowKey1, mystorageaccount, and YOUR_STORAGE_ACCOUNT_KEY with your specific values.
Use the Remove-AzStorageTableEntity cmdlet to delete an entity.
Remove-AzStorageTableEntity -TableName MyTable `
-PartitionKey "PartitionKey1" `
-RowKey "RowKey1" `
-Context $ctx
Ensure you have set up your storage account context ($ctx) beforehand.
The Azure SDK for .NET provides methods to interact with Azure Storage Tables.
using Azure.Data.Tables;
// ...
var connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
var tableName = "MyTable";
var partitionKey = "PartitionKey1";
var rowKey = "RowKey1";
var client = new TableClient(connectionString, tableName);
try
{
client.DeleteEntity(partitionKey, rowKey);
Console.WriteLine($"Entity with PartitionKey='{partitionKey}' and RowKey='{rowKey}' deleted successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error deleting entity: {ex.Message}");
}
Make sure to install the Azure.Data.Tables NuGet package.
The Azure SDK for Python simplifies table operations.
from azure.data.tables import TableClient
# ...
connection_string = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
table_name = "MyTable"
partition_key = "PartitionKey1"
row_key = "RowKey1"
table_client = TableClient.from_connection_string(connection_string, table_name)
try:
table_client.delete_entity(partition_key, row_key)
print(f"Entity with PartitionKey='{partition_key}' and RowKey='{row_key}' deleted successfully.")
except Exception as e:
print(f"Error deleting entity: {e}")
Install the SDK using: pip install azure-data-tables
Leverage the Azure SDK for Java for table entity management.
import com.azure.data.tables.TableClient;
import com.azure.data.tables.TableServiceClient;
import com.azure.data.tables.TableServiceClientBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;
// ...
String connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
String tableName = "MyTable";
String partitionKey = "PartitionKey1";
String rowKey = "RowKey1";
TableServiceClient tableServiceClient = new TableServiceClientBuilder()
.connectionString(connectionString)
.buildClient();
TableClient tableClient = tableServiceClient.getTableClient(tableName);
try {
tableClient.deleteEntity(partitionKey, rowKey);
System.out.println("Entity deleted successfully.");
} catch (Exception e) {
System.err.println("Error deleting entity: " + e.getMessage());
}
Ensure you have the Azure Tables dependency in your project.
You can also delete entities directly using the Azure Storage Tables REST API.
GET https://<storage-account-name>.table.core.windows.net/<table-name>(PartitionKey='<partition-key>',RowKey='<row-key>')?sv=<sas-token> HTTP/1.1
Accept: application/json;odata=fullmetadata
DataServiceVersion: 3.0;NetFx
Content-Type: application/json
DELETE
You will need to construct the URL with your storage account name, table name, partition key, row key, and a valid Shared Access Signature (SAS) token or use authentication with Azure AD.