|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Guid / uniqueidentifier ...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 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 quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ "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 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. 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 |
|||||||||||||||||||||||