[thelist] Key ID of Record Just Created?

Mark Rees mrees at itsagoodprice.com
Tue Aug 23 11:22:34 CDT 2005


Please send replies to the list (hit reply-all instead of reply). My reply
inline

> > > In ASP.NET / VB.NET, is it possible to discover the key_id of a record
> just
> > > created?  Key ID column is doc_id.
>
>
> > If key_id is an SQL Server identity column, then
> > SELECT @@IDENTITY
> > after the insert will return this value. It is my understanding that
even
> if
> > another process inserts another record in between times, this will
return
> > the value you want, ie the key_id of the record just inserted by your
> script
>
>
> That is exactly what I'm after.  The column name is doc_id, and it is
> designated in MS SQL as the key id for the table.  I'm not sure what you
> mean by "If key_id is an SQL Server identity column".

Try looking here
http://www.google.co.uk/search?q=SQL+Server+identity+column&sourceid=mozilla
-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:e
n-GB:official

Have you got SQL server Enterprise Manager installed on your PC? If so, you
should have Books Online as well. It is an invaluable resouce for answering
questions such as this.

Also, When I use
> SELECT @@IDENTITY, how do I then re-use this later?  For example, later I
> want to run a query against this record, how do I refer to the value?  Can
I
> add it to a variable, such as
>
> 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

>
> ??
>
> TIA!!!
>
>




More information about the thelist mailing list