Re: @@Identity

From: Michael L John (mjohn_at_emscharts.com)
Date: 09/22/04


Date: Wed, 22 Sep 2004 13:51:35 -0400

Scott, you obviously are an idiot.
But, I will attempt to answer your LAST post because it is the only one that
makes sense.

There are now 4 highly skilled and very experienced people that did not
understand anything you asked in your OP, so I guess all of them (us) are
idiots.

A SQL server database table can have one integer field designated as an
identity field. This value will auto increment when a new row is inserted
into a table that has an identity field. The starting values, as well as
the number that is incremented, can be defined by the user.

If you are inserting a row with your ADO.Net code that will increment the
identity value, and need to reliably retrieve this value, you can,
immediately after the INSERT statement, run "SELECT @@Identity". This will
return an integer that is the LAST IDENTITY VALUE inserted into a table.

As Bill pointed out, there are issues when using the GLOBAL SQL VARIABLE
@@identity.

Assume you have 2 users that are both inserting a record in the same table.
User A inserts record 10, user B inserts record 11. Unless your code has
perfect timing, "SELECT @@identity" will return 11.
In a much worse case, assume there are 10 users inserting records into 10
tables with identity columns defined. In that case, who knows what value
you may get back from "SELECT @@identity"

You will be better served by using "SELECT SCOPE_IDENTITY()" in your code.
The value returned by this FUNCTION is the identity specific to the CURRENT
SCOPE.

As Mary also said, READ BOOKS ONLINE. This will make things much clearer.
Unless you do not really know how to read.

Good Luck
Michael L John

"Scott M." <NoSpam@NoSpam.com> wrote in message
news:ujJJ43FoEHA.3684@TK2MSFTNGP10.phx.gbl...
> Roy, I asked about @@Identity because I didn't know about it. If I
> misused the term "parameter", it was because I lacked the information I
> was looking for in the first place.
>
> The OP was not, as you say, "non-sensical". The other replies seemed to
> have gotten what I was asking. Might I suggest that you not reply at all
> if you don't understand the post?
>
>
> "Roy Fine" <rlfine@twt.obfuscate.net> wrote in message
> news:%23xhgyBEoEHA.3224@tk2msftngp13.phx.gbl...
>> Scott,
>>
>> read your orignal post - I said there is no such thing as an @@Identity
>> parameter - that was what you were asking how to set. Your original post
>> was nonsensical! your your own sake (and professional reputation) - one
>> would have to strongly advise you against asking people to go back and
>> read
>> it.
>> roy
>>
>>
>> "Roy Fine" <rlfine@twt.obfuscate.net> wrote in message
>> news:%237Y%23LMDoEHA.592@TK2MSFTNGP11.phx.gbl...
>>>
>>> "Scott M." <NoSpam@NoSpam.com> wrote in message
>>> news:Oi$nLKpnEHA.2028@TK2MSFTNGP10.phx.gbl...
>>> > Wow Mary, thanks for the attitude!
>>> >
>>> > I don't know why you keep telling me that @@Identity it not
>>> > technically
>> a
>>> > field. I know that and it is beside the point of my question. It
>>> > does
>>> > return a field and it doesn't take a rocket scientist to figure that
>>> > out
>>> > what I meant in my OP.
>>> >
>>>
>>> >> How do I set the @@Identity parameter for data that
>>> >> has been read in from a
>>> >> database? I have read in data via a command
>>> >> (SELECT statement) and am
>>> >> trying to build a good UPDATE statement and
>>> >> want to use the @@Identity field.
>>>
>>> Scott - I have read the above statement from your OP - and I have read
>>> it
>>> several times sincethis thread has started, and I must say "your OP
>>> makes
>> no
>>> sense". There is no such thing as an @@Identity parameter - so I would
>> walk
>>> away from the OP and try again.
>>>
>>> roy fine
>>>
>>>
>>>
>>
>>
>
>



Relevant Pages

  • Re: @@Identity
    ... like 6 posts ago in this thread. ... This value will auto increment when a new row is ... >> into a table that has an identity field. ... >> If you are inserting a row with your ADO.Net code that will increment ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: @@Identity
    ... like 6 posts ago in this thread. ... This value will auto increment when a new row is inserted ... > into a table that has an identity field. ... > If you are inserting a row with your ADO.Net code that will increment the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Convert Mysql table schema to Oracle table
    ... Whomever is ... inserting the data into the table is still responsible for inserting a ... valid key and keeping track of what is 'valid'. ... CREATE SEQUENCE SEQ_BUILD_IDS INCREMENT BY 1 START WITH 1000; ...
    (comp.databases.oracle.server)
  • Re: Increment final value in for statement
    ... For more information on inserting and deleting rows and maintaining ... > When I run this lastrow doesn't increment and last row stays at the original ...
    (microsoft.public.excel.programming)
  • Re: Deadly Genesis #1 (potential spoiler)
    ... >>>for inserting such an event into that time without making the other ... >>>parts of the story need a seemingly random Prof X mindwipe. ... > The guy knows Scott and thinks Scott should know him. ... chooses not to enlighten Cyclops in regards to certain events. ...
    (rec.arts.comics.marvel.universe)