Connecting Tech Pros Worldwide Forums | Help | Site Map

Using @@IDENTITY in manual commit mode

Deepak
Guest
 
Posts: n/a
#1: Jul 20 '05
Hi,

I'm using the JDBC API's to access a MS-SQL 2000 DB.I have a
manual-commit transaction block involving multiple inserts and
updates. One of the step involves retrieving the auto generated key
(Identity column) which, I presume can be done with @@IDENTITY. My
Question is: Will @@IDENTITY work if Auto Commit is turned off?

John Bell
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Using @@IDENTITY in manual commit mode


Hi

If you are using SQL Server 2000 then the SCOPE_IDENTITY function should be
used instead of @@IDENTITY. @@IDENTITY and SCOPE_IDENTITY will return the
last Identity value created by that session, therefore if you have triggers
that insert data into a table containing an identiity value it will not
return the value you are expecting. Not using AUTO_COMMIT will not effect
this behaviour.

John

"Deepak" <deepak.j@bigpond.com> wrote in message
news:bfa6e05a.0310162309.b0d778e@posting.google.co m...[color=blue]
> Hi,
>
> I'm using the JDBC API's to access a MS-SQL 2000 DB.I have a
> manual-commit transaction block involving multiple inserts and
> updates. One of the step involves retrieving the auto generated key
> (Identity column) which, I presume can be done with @@IDENTITY. My
> Question is: Will @@IDENTITY work if Auto Commit is turned off?[/color]


Closed Thread