[thelist] Key ID of Record Just Created?

Ken Schaefer ken.schaefer at gmail.com
Sat Aug 27 03:34:43 CDT 2005


On 8/24/05, Chris Hayes <chris at lwcdial.net> wrote:
> 
> >> DIM valDocID as Integer = SELECT @@IDENTITY
> >
> > I don't know anything about .NET syntax, but basically yes, you will have
> > to
> > run that SELECT query, and assign the results to a variable
> 
> 
> Don'y know if it applies to ASP with MS/MY SQL but might advise a
> transaction lock around the insert and the select to ensure you retrieve the
> correct ID.
> 
> Anybody?

With MS SQL Server, this is unnecessary. Both @@IDENTITY and
Scope_Identity are scoped appropriately. Provided you use the same
connection to the database, you will always get an identity value that
you created, and not one created by someone else.

Cheers
Ken


More information about the thelist mailing list