不允许删除表数据的触发器
USE [AdventureWorks] GO CREATE TRIGGER [HumanResources].[dEmployee] ON [HumanResouces].[Employee] INSTEAD OF DELETE NOT FOR REPLICATION AS BEGIN SET NOCOUNT ON; DECLARE @DeleteCount int; SELECT @DeleteCount = COUNT(*) FROM deleted; IF @DeleteCount > 0 BEGIN RAISERROR (N'Employees cannot be deleted .They can only be marked as not current .',--message 10,--severity. 1);--State. --回滚事物 IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END END; END; GO