本文介绍了如何在scope_identity的帮助下获取身份值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您能帮助我解决问题,我将不胜感激.
我有在TRIGGER中实现的scope_identity().
I would be grateful if you could help me to solve the problem.
I have scope_identity() that implemented in TRIGGER.
ALTER TRIGGER TempProcTrig
ON Table_temp2
AFTER insert
AS
BEGIN
declare @TempIdentity int
set @TempIdentity =scope_identity()
insert Table_Temp(TempID)
values(@TempIdentity)
END
触发TRIGGER后,@ TempIdentity会获取Identety列字段,并将此值设置到另一个表中.
但是,在触发TRIGGER之后,@ TempIdentity始终为NULL.
为什么TempIdentity无法获得Identity字段?我应该在代码中更改哪些内容?
预先谢谢您.
When TRIGGER is fired @TempIdentity gets Identety column field, and set this value into another table.
But,allways after TRIGGER is fired @TempIdentity gets NULL.
Why TempIdentity dosen''t get Identity field?What should i change in my code?
Thank you in advance.
推荐答案
ALTER TRIGGER TempProcTrig
ON Table_temp2
AFTER insert
AS
BEGIN
insert Table_Temp(TempID)
SELECT TempID FROM inserted
END
Alter Table Table_temp2 Add TempId Int IDENTITY(1,1) Not null
然后,您可以使用已经向您展示Rahul Dhoble的代码.
then you can use the code that has already showed you Rahul Dhoble.
这篇关于如何在scope_identity的帮助下获取身份值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!