Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@@identity problem

Status
Not open for further replies.

poptcat

Programmer
Jul 16, 2007
3
RO
Hi.
I have two tables tableA and tableB; both have a primary key (integer data type).
There is a trigger on insert after on tableA. Inside this trigger I put an insert on tableB.
So given the following situation:

insert into tableA....
select @@identity from sys.dummy

the value of identity is changed by that insert inside of the trigger on tableA?
I noticed it's not changed but I can't explain this.
Popa Gabriel
 
Try Scope_Identity() instead.

Code:
select Scope_Identity() As NewIdentityValue

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Yep. That is the expected behavior of @@IDENTITY. Follow George's example code.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Thanks for your response. It helped me a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top