Skip to Content.
Sympa Menu

freetds - Re: [freetds] SELECT @@IDENTITY AS InsertID

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Pickett, David" <David.Pickett AT phlx.com>
  • To: 'FreeTDS Development Group' <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] SELECT @@IDENTITY AS InsertID
  • Date: Wed, 16 Nov 2005 10:07:45 -0500

Hi,

Doesn't the 'select max(ID)' after insert, even within a transaction, leave
a narrow time window for some other process to commit higher values to the
table (unless you somehow can qualify the select for just your rows, e.g.,
"where insert_id = ? ", which would slow it, or lock the table or your view
of it)?

If the @@IDENTITY describes rows inserted by the trigger, and can you
backtrack relationally using the @@identity of the final row to find the
original row?

Liking inserting insert triggers and @@identity but hating stored procedures
does not seem to be well supported by SQL Server.

Maybe the trigger could insert the other row *first*, so the final
@@identity is the one you want?

Best regards,

David

-----Original Message-----
From: Lowden, James K [mailto:LowdenJK AT bernstein.com]
Sent: Wednesday, November 16, 2005 9:47 AM
To: FreeTDS Development Group
Subject: Re: [freetds] SELECT @@IDENTITY AS InsertID


> From: Shaun Craig
> Sent: Wednesday, November 16, 2005 6:01 AM
>
> At present i've taken out my select @@identity and replaced it with
> a select top 1 ... order by ...desc, this also gets me my identity,
> its safe for each 'Event' as another 'Event' from the same device
> cant be processed till this 'Event' would be finished.
>
> I dont use any stored procedures as code will have to be converted
> to connect to mysql eventually.

Your code will be standards-conformant and faster if you use 'select
max(ID)' instead of "top 1 ... order by". It's much less work for the
server, especially if (as should be the case) the ID is the first
element of a unique index.

--jkl

-----------------------------------------
The information contained in this transmission may be privileged and
confidential and is intended only for the use of the person(s) named
above. If you are not the intended recipient, or an employee or agent
responsible
for delivering this message to the intended recipient, any review,
dissemination,
distribution or duplication of this communication is strictly prohibited. If
you are
not the intended recipient, please contact the sender immediately by reply
e-mail
and destroy all copies of the original message. Please note that we do not
accept
account orders and/or instructions by e-mail, and therefore will not be
responsible
for carrying out such orders and/or instructions. If you, as the intended
recipient
of this message, the purpose of which is to inform and update our clients,
prospects
and consultants of developments relating to our services and products, would
not
like to receive further e-mail correspondence from the sender, please
"reply" to the
sender indicating your wishes. In the U.S.: 1345 Avenue of the Americas,
New York,
NY 10105.
_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds




Archive powered by MHonArc 2.6.24.

Top of Page