用于更新触发器 - 将值插入历史表中
这就是我现在所拥有的:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要列出所有列
* 与 DELETED 中存在的列一样多 + getdate() 的列
You need to list out all the columns
* as many columns as exists in DELETED + column for getdate()