[thelist] Free Tip about SQL

Jason Handby jasonh at corestar.co.uk
Fri Jul 18 11:35:17 CDT 2003


Jay wrote:
> Can't you do (if for instance the id field is named ID)
>
> SELECT MAX(ID) FROM foo
>
> ?

No you can't -- someone else might manage to add another new record *after*
your record got added and *before* your select statement gets run. In which
case your select statement would pick up their new record, which is not what
you want...

Honestly, use @@IDENTITY, or LAST_INSERT_ID(), or whatever equivalent your
database provides -- anything else is a really bad idea!



Jason



More information about the thelist mailing list