[freetds] SELECT @@IDENTITY AS InsertID
ZIGLIO, Frediano, VF-IT
Frediano.Ziglio at vodafone.com
Wed Nov 16 09:58:31 EST 2005
> > 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.
Yes, however if another connection insert a row just after my insert
max(id) returns wrong id... I think that the best option is to fix our
pool server to not reuse connection for every query. It would be perfect
if it could also "rollback" to a safe state (rollback all transactions,
close cursors, drop temporary objects and so on)
More information about the FreeTDS