TRIGGER
先新增資料表:LogAttachCables
欄位與AttachCables相同,另增加LogId,LogTime,LogType三個欄位。
在AttachCables按右鍵,新增觸發程序,修改指令:
CREATE TRIGGER [dbo].[LogDelete]
ON [dbo].[AttachCables] for delete
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
insert into [LogAttachCables](LogType, Id, Type, Status, Name, Contact, Phone, Address, Email, CreateTime, SubmitTime, File1, File2, File3, File4, File5, File6, File7, File8, File9, TownVerifyTime, TownApproveNo, TownApproveFile, TownApproveDate, BusinessVerifyDescription, BusinessVerifyTime, Year, Months, DepositStatus, BeginTime, EndTime, UserId, GroupId, TownId, CableId, PaymentId)
select 'Delete', Id, Type, Status, Name, Contact, Phone, Address, Email, CreateTime, SubmitTime, File1, File2, File3, File4, File5, File6, File7, File8, File9, TownVerifyTime, TownApproveNo, TownApproveFile, TownApproveDate, BusinessVerifyDescription, BusinessVerifyTime, Year, Months, DepositStatus, BeginTime, EndTime, UserId, GroupId, TownId, CableId, PaymentId from deleted
END
-----------------------------------------------------------------------------------
CREATE TRIGGER [dbo].[LogInsert]
ON [dbo].[AttachCables] for insert
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
insert into [LogAttachCables](LogType, Id, Type, Status, Name, Contact, Phone, Address, Email, CreateTime, SubmitTime, File1, File2, File3, File4, File5, File6, File7, File8, File9, TownVerifyTime, TownApproveNo, TownApproveFile, TownApproveDate, BusinessVerifyDescription, BusinessVerifyTime, Year, Months, DepositStatus, BeginTime, EndTime, UserId, GroupId, TownId, CableId, PaymentId)
select 'Insert', Id, Type, Status, Name, Contact, Phone, Address, Email, CreateTime, SubmitTime, File1, File2, File3, File4, File5, File6, File7, File8, File9, TownVerifyTime, TownApproveNo, TownApproveFile, TownApproveDate, BusinessVerifyDescription, BusinessVerifyTime, Year, Months, DepositStatus, BeginTime, EndTime, UserId, GroupId, TownId, CableId, PaymentId from inserted
END
-----------------------------------------------------------------------------------
CREATE TRIGGER [dbo].[LogUpdate]
ON [dbo].[AttachCables] for update
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
insert into [LogAttachCables](LogType, Id, Type, Status, Name, Contact, Phone, Address, Email, CreateTime, SubmitTime, File1, File2, File3, File4, File5, File6, File7, File8, File9, TownVerifyTime, TownApproveNo, TownApproveFile, TownApproveDate, BusinessVerifyDescription, BusinessVerifyTime, Year, Months, DepositStatus, BeginTime, EndTime, UserId, GroupId, TownId, CableId, PaymentId)
select 'Update', Id, Type, Status, Name, Contact, Phone, Address, Email, CreateTime, SubmitTime, File1, File2, File3, File4, File5, File6, File7, File8, File9, TownVerifyTime, TownApproveNo, TownApproveFile, TownApproveDate, BusinessVerifyDescription, BusinessVerifyTime, Year, Months, DepositStatus, BeginTime, EndTime, UserId, GroupId, TownId, CableId, PaymentId from inserted
END