How to delete an entire Azure Table in one command
Deleting an Entire Azure Table
- How to delete an entire Azure table is quite easy.
- I get this question quite often. I normally would not create such a simple post.
- Most developers think they need to delete rows, one row at a time.
- But that isn't true.
- There is support for deleting a whole table.
- Here is the REST-based approach
- Here is the approach using the .NET libraries
Sample.cs
Sample.cs | |
12345678910 | // Retrieve storage account from connection stringCloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the table clientCloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Delete the table it if existstableClient.DeleteTableIfExist("people"); |
Cheers,
Hope this helps.
Comments
Anonymous
September 25, 2012
One thing I would like to point out is that this operation will actually start deletion operation. Windows Azure Storage service would mark this table as "To Be Deleted" (or something like it) so that any attempt to access this table (like read/write etc.) will throw an error. However the actual deletion process could take a lot of time depending on the number of entities you have in that table. While the table "is being deleted" any attempt to recreate the table will result in an error.Anonymous
January 10, 2013
actually I have a azure table with about 1~2 million records. I've tried several times to delete the table but got 500 error. I don't know whether there is any other better idea to delete one azure table. [send me your code at bterkaly@microsoft.com]Anonymous
February 22, 2016
The trick for quick clearing is simple. Keep a shortcut to your container hosting the table in your API's. Then, use the shortcut for reference / looking up container name during runtime. That is, the table name is virtual and referenced by a shortcut in your code. When you want to clear a container (table) just change your shortcut to reference a different container and then clear the old one. Swap back and forth between containers. INSTANT clear with no downtime! Since your API's will be referencing a shortcut the underlying table will be swapped out on the fly, but your code won't know it happened. Now Microsoft can take as long as it wants to clear the old table. Of course, you'll need to keep a set of round-robin containers and possible storage accounts for this, but you DID keep everything abstracted right?