SQL Server 表建Trigger
USE [***]--数据库更新 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER [dbo].[triTable1Update] ON [dbo].[Table1] AFTER UPDATE AS --if @@rowcount<=1 return BEGIN if update([status]) begin insert into Table1_log select d.id,d.ftype,d.[count],d.mdte,d.mtme,d.status,d.quality,d.errcount,d.rdate,d.rtime,d. remark,d.lmuser,d.pdtype,d.NXTType,d.CQty,d.location,'O',getdate() from deleted d,inserted i where d.id = i.id and d.[status] <> i.[status] insert into Table1_log select i.id,i.ftype,i.[count],i.mdte,i.mtme,i.status,i.quality,i.errcount,i.rdate,i.rtime,i.remark,i.lmuser,i.pdtype,i.NXTType,i.CQty,i.location,'N',getdate() from deleted d,inserted i where d.id = i.id and d.[status] <> i.[status] end END
USE [***]--数据库插入 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER [dbo].[triTableinserted] --插入 ON [dbo].[Table] AFTER insert AS BEGIN insert into Table_log select i.mnid,i.model,i.lockdate,i.locktime,i.lockreason,i.location,i.lockuser,i.lockPC,i.unlockdate,i.unlocktime,i.unlockresason,i.unlockuser,i.unlockPC,i.process,'I',convert(datetime,getdate(),113) from inserted i END
USE [***] GO /****** Object: Trigger [dbo].[trismtmdlDelete] Script Date: 2023/1/13 11:07:51 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[triTableDelete] ON [dbo].[Table] AFTER DELETE AS BEGIN insert into Table_log select i.submodel,i.pcbapn,i.[description],i.cycle,i.ptype,i.unit,i.ng,i.[version],i.PrdType,i.reserve1,i.reserve2,i.reserve3,i.reserve4,i.minsqg,i.maxsqg,i.chglinecost,i.onlineMan,i.offlineMan,i.repanel,i.repaneltype,i.board_partno,i.ptype_desc,i.pcba_type,i.ai_progname4,i.ProcessKey,i.lmdate,i.lmtime,i.lmuser,'D',getdate() from deleted i END