Prevent to delete the database or server

Prevent to delete the database or server

It might be easy to answer this question, can we restore an SQL Server database in Azure if we delete the server? Microsoft here answer this question,  If you delete a server, all its databases are also deleted and can't be recovered. You can't restore a deleted server. If LTR backups were taken, individual databases can be restored to a different server.

Can we restore a deleted database in Azure?

In so many cases next question is “We have not set the LTR backup, is there any way to…” the answer sadly would be no…

What can we prevent to delete the database or server by accident? Is there a way to place purge protection on SQL Server?

In this post I want to explain how you can easily enable the lock in Azure Portal.

In the first step go to database server page in Azure Portal from the left blade choose “Lock” like the following screenshot.

can we prevent to delete the database or server by accident?

Put Lock name and choose the type “Delete” then save it, it take a couple of minutes to save the lock.

Then I try to delete the server from Azure Portal, as you see you’ll get the following error message! You’re not allow to delete the server or any database in this server!

Failed to delete the server, Error Code:409

If you wish to delete the database or server first go to Lock in database page and delete the item which you created in very first step. Then if you try to delete the database or server you can do it!

As you see only with a simple click and take one or two minutes you could save your database for any delete by accident!