1、創建實例數據庫和表:
create database demo
go
use demo
create table T_User(UserName varchar(64))
go
2、創建數據庫觸發器:
create trigger prevent_drop_table ON DATABASE FOR DROP_TABLE
AS
RAISERROR('Not allowed to drop tables.', 10, 1)
PRINT 'DROP TABLE attempt in database ' + DB_NAME() + '.'
PRINT CONVERT (nvarchar (1000),EventData())
ROLLBACK
GO
3、測試:
use demo
--測試刪除表
drop table T_User
--但對臨時表沒有作用