SQL SERVER deletes the database and prohibits the creation of triggers to delete the database

Foreword:
When the server is running, unexpected operations are very dangerous. If the library is deleted accidentally, it will be very broken. Although I don't want to appear. But you can guarantee that there is no accident. So it is very important to build a trigger to prohibit deleting the library. And you have to imagine all accidental operations.
How to delete the library?
If you really get rid of the library, don't overwrite it with the old version. In this way, your data may really not be retrieved. You can find someone at TB Mall to restore it. A few hundred should be.
If it is covered. That would be unfortunate. Various files in the library may be lost, and various accidents may occur in the restored library. For example, the stored procedure cannot be opened.
postscript: If the library is not important and the data can be supplemented, then there is no need to restore it, just restore the old backup.
Prohibit deleting database triggers

  1. First create a new library, the library name is arbitrary.
--禁止删除库触发器。
create trigger [trad] on all server
with execute as 'sa'
for drop_database
as
begin
 set nocount on
  
 rollback tran
  
 print 'Don''t allow to drop database..'

END

  1. Try to delete the database. When deleting the database, it will mention that it is not allowed to delete the database.
    Insert picture description here
  2. If you really need to delete a library. You can delete the trigger. Delete the library.
    Insert picture description here

Guess you like

Origin blog.csdn.net/hello_mr_anan/article/details/105795547