不允许删除表数据的触发器

mac2022-06-30  115

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

 

转载于:https://www.cnblogs.com/siyunianhua/archive/2011/12/26/2302671.html

最新回复(0)