/****** Object: Trigger [dbo].[trg_del] Script Date: 01/01/2016 12:58:28 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TRIGGER [dbo].[trg_del] ON [dbo].[Common_Header] INSTEAD OF DELETEAS BEGIN DECLARE @cou INT DECLARE @headerid UNIQUEIDENTIFIER SELECT @cou = COUNT(*) FROM deleted; SELECT @headerid = id FROM deleted IF ( @cou > 1 ) RAISERROR('数据不允许删除!', 16, 1) ELSE DELETE FROM [Common_Header] WHERE id = @headerid ENDGO
CREATE TABLE [dbo].[Common_Header]([ID] [uniqueidentifier] NOT NULL,[Subject] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[ApplicantAD] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[ApplicantName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[CountryCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[CountryName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[CompanyCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[CompanyName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[DivisionCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[DivisionName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[LBUCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[LBUName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[CostCenter] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,[Email] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,[CreatedDate] [datetime] NULL,[QueueID] [uniqueidentifier] NULL,[Status] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL) ON [PRIMARY]GOALTER TABLE [dbo].[Common_Header] ADD CONSTRAINT [PK_Common_Header] PRIMARY KEY CLUSTERED ([ID]) ON [PRIMARY]GOCREATE NONCLUSTERED INDEX [NonClusteredIndex-20150603-113054] ON [dbo].[Common_Header] ([QueueID]) ON [PRIMARY]GO