用于更新触发器 - 将值插入历史表中

发布于 2024-10-20 16:21:23 字数 866 浏览 1 评论 0原文

这就是我现在所拥有的:

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)

我该把这个放在哪里???

先感谢您!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-10-27 16:21:23

您需要列出所有列

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

* 与 DELETED 中存在的列一样多 + getdate() 的列

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()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文