这就是我现在所拥有的:
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
但我不断收到以下错误:插入错误:列名或提供的值数与表定义不匹配。
我在想,也许最好写下触发器中的所有字段,以确保每个符号匹配,但我似乎无法弄清楚这样做的格式。
insert into tblHistorySource (value1, value2) values (value1, value2)
我把它放在哪里???
提前谢谢!
答案 0 :(得分:1)
您需要列出所有列
....
begin try
INSERT INTO tblHistorySource (value1, value2, somedatecolumn) -- all the columns*
select value1, value2, getdate() -- al
from [DELETED]
end try
....
* getdate()
的DELETED +列中存在的列数