触发器,禁止删除某记录
代码
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER TRIGGER [dbo].[DenyDelete]
ON [dbo].[tbsmstemplate]
for delete
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
if exists (select 1 from deleted where fsmstemplateid in (22,23,24,25))
begin
RAISERROR ('不能删除id=0的记录', 16, 1)
ROLLBACK TRANSACTION
end
END
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER TRIGGER [dbo].[DenyDelete]
ON [dbo].[tbsmstemplate]
for delete
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
if exists (select 1 from deleted where fsmstemplateid in (22,23,24,25))
begin
RAISERROR ('不能删除id=0的记录', 16, 1)
ROLLBACK TRANSACTION
end
END
走向地狱的途中,不小心走了程序员这条路,路上一个个黑心的老板,和暗无天日的加班,我才发现,通往地狱的路径中,我们这行是最短的。