Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@@Identity Equivalent for uniqueidentifier

Status
Not open for further replies.

BoulderBum

Programmer
Jul 11, 2002
2,179
US
I seem to remember something similar to @@Identity for selecting the primary key of the previously inserted record (in this case a GUID).

Does anyone know what it is?

[COLOR=blue gainsboro]
Get a FREE iPod by helping me get mine! Click my referrer link:

More about the company and deal:
[/color]
 
@@identity would be correct. I use this in a few of my stored procs in order to populate another table with the primary key value of a record I have just inserted.

tim
 
I've seen posts from people that I know have much more expertise then my self recommending not using @@IDENTITY but instead SCOPE_IDENTITY. My understanding is that use can lose the value of @@INDENTITY in nested SPs. Maybe the gurus can elaborate or correct me. This is what I see in BOL:

@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the last value inserted into the IDENTITY column of a table.

@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
 
Try newID() for uniqueindentifier. Use newid() to generate a GUID and assign it to a variable before inserting the recored and you can have the variable returned at the end of the SP

Sunil
 
Try newID() for uniqueindentifier."

That's what I do now, I was just wondering about the alternative. The default value for a certain column IS NewID() so I don't have to explicitly insert it per se, my problem is that trying to use @@IDENTITY after NOT explicitly inserting results in a NULL value. I'll try that SCOPE_IDENTITY thing. That sounds like it may be what I need.

[COLOR=blue gainsboro]
Get a FREE iPod by helping me get mine! Click my referrer link:

More about the company and deal:
[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top