Capturing rowguid value after insert

  • I am new to SQL server so I may be overseeing something totally obvious to you. After an insert, how do I get the value of a GUID that was generated by SQL Server (default value in a uniqueidentifier column '(newid())'). For an identity column, I see that one can use @@IDENTITY. Is there something similar for GUIDs?

  • This probably isn't exactly what you're looking for, but it's how i get around it.

    In my stored proc. I use a variable to hold a newid() and use that for the insert and pass it back out as an output param. If you're using .NET you can create a guid in code and pass it in that way too so that you still have referece to the row.

    Again, probably not exactly what you're looking for, but it's how i've gotten around it.

  • I do it by doing an INSERT in the stored prodedure, which has SQL Server create and assign the GUID. Then I do a select to read the GUID using the key values in the WHERE clause.

    Not the ideal solution, but with SQL Server 2000 I don't think there is an ideal solution. Does anyone know if Yukon fixed this so we can use @IDENTITY (etc.) with GUID values?

    Thanks,

     

  • You'd think that with all the replication improvements from 7.0 forward that they would address this since GUIDs are used as unique identifiers in replicated DBs.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply