简体   繁体   English

更新触发器-将值插入历史记录表

[英]for Update Trigger - to insert values into a History Table

This is what i have now: 这就是我现在所拥有的:

GO
/****** Object:  Trigger [dbo].[trg_SourceHistory]    Script Date: 03/08/2011 14:38:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trg_SourceHistory] 
ON [dbo].[tblSource]
for UPDATE
AS 
begin try
INSERT INTO tblHistorySource
select *, getdate()
from [DELETED]
end try
begin catch
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
RAISERROR('Error in Source Hisotry Trigger' ,16,1)
ROLLBACK TRAN
END CATCH

but i keep getting the following error: Insert Error: Column name or number of supplied values does not match table definition. 但是我一直收到以下错误:插入错误:列名或提供的值数与表定义不匹配。

i was thinking that maybe it would be a good idea to write out all the fields in the trigger to make sure everythign matches up, but i can't seem to figure out the format to do so. 我当时在想,在触发器中写出所有字段以确保所有人匹配都可能是个好主意,但是我似乎无法弄清楚这样做的格式。

insert into tblHistorySource (value1, value2) values (value1, value2)

where do i put this??? 我在哪里放这个???

Thank you in advance! 先感谢您!

You need to list out all the columns 您需要列出所有列

....
begin try
INSERT INTO tblHistorySource (value1, value2, somedatecolumn)  -- all the columns*
select value1, value2, getdate()   -- al
from [DELETED]
end try
....

* as many columns as exists in DELETED + column for getdate() * DELETED + getdate()列中存在的列数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM