我们只想通过写入触发器维护MS SQL中的表日志(每个更改)历史记录
我试过但没有工作
CREATE TRIGGER [dbo].[update_ServiceDescriptionTable]
ON ServiceDescriptionMaster
After UPDATE
AS
BEGIN
declare @Rate money;
Select @Rate = Rate from inserted;
update [dbo].[ServiceDescriptionMasterlog] set Rate = @Rate
where Service_Description = '';
END
答案 0 :(得分:1)
1)创建与" ServiceDescriptionMasterlog"相同的表格。 with one Extra Field(Column)Entry_DateTime set default bind getdate()method。
2)在" ServiceDescriptionMaster"上写一个触发器表格如下:
ALTER TRIGGER [dbo].[ServiceDescriptionMaster_OnUpdate]
ON [dbo].[ServiceDescriptionMaster]
After UPDATE
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [dbo].[ServiceDescriptionMasterLog]
(S_No,Rate,.....)
select S_No,Rate,.....
from Deleted;
END
你也可以继续删除:
ALTER TRIGGER [dbo].[ServiceDescriptionMaster_OnDelete]
ON [dbo].[ServiceDescriptionMaster]
For Delete
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [dbo].[ServiceDescriptionMasterLog]
(S_No,Rate,.....)
select S_No,Rate,.....
from Deleted;
END