Home All Groups Group Topic Archive Search About

Guid / uniqueidentifier ...

Author
28 Apr 2006 10:52 AM
Jarod
Hey
I have database ( ASP.Net membership ) that use uniqueindentifiers. I don't
need to use this tables manualy so I thought I will just create another
table that uses userGUID and UserID( int ), so it will map pretty quickly,
and applications accustomed to work with UserID as integer will work. My
idea is: Create trigger that uses Insert "event" and than copy newly created
GUID to new table with auto increment integer primary key, and mapping is
ready ;) But how to get last created GUID ? Something like @@Identity for
integers... I need the same for GUID ;) Or any other good solution.
Jarod

Author
28 Apr 2006 10:57 AM
Tibor Karaszi
There's no version of @@IDENTITY (or the preferred SCOPE_IDENTITY()) for the NEWID() function. So
you just generate the value in the code that will later do the insert and you now have the value. If
that is not an option, then just do a SELECT with a WHERE clause for the natural key for the table
and pick up the value.

Show quote
"Jarod" <blueice@NOSPAM.gazeta.pl> wrote in message
news:%23K%23yPGraGHA.3376@TK2MSFTNGP05.phx.gbl...
> Hey
> I have database ( ASP.Net membership ) that use uniqueindentifiers. I don't need to use this
> tables manualy so I thought I will just create another table that uses userGUID and UserID( int ),
> so it will map pretty quickly, and applications accustomed to work with UserID as integer will
> work. My idea is: Create trigger that uses Insert "event" and than copy newly created GUID to new
> table with auto increment integer primary key, and mapping is ready ;) But how to get last created
> GUID ? Something like @@Identity for integers... I need the same for GUID ;) Or any other good
> solution.
> Jarod
Author
28 Apr 2006 11:08 AM
Tony Rogerson
Just use the 'inserted' system table available in the trigger, it contains a
copy of the newly inserted row(s) so your GUID will be there.

Like Tibor states, there is no equiv for @@IDENTITY / SCOPE_IDENTITY() for a
uniqueidentifier.

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials


Show quote
"Jarod" <blueice@NOSPAM.gazeta.pl> wrote in message
news:%23K%23yPGraGHA.3376@TK2MSFTNGP05.phx.gbl...
> Hey
> I have database ( ASP.Net membership ) that use uniqueindentifiers. I
> don't need to use this tables manualy so I thought I will just create
> another table that uses userGUID and UserID( int ), so it will map pretty
> quickly, and applications accustomed to work with UserID as integer will
> work. My idea is: Create trigger that uses Insert "event" and than copy
> newly created GUID to new table with auto increment integer primary key,
> and mapping is ready ;) But how to get last created GUID ? Something like
> @@Identity for integers... I need the same for GUID ;) Or any other good
> solution.
> Jarod

AddThis Social Bookmark Button