Saturday, February 11, 2012

a GUID question

does SQL Server have the equivalent of the Identity or Scope_Identity functions that can be used to return the last GUID PK?I do not think so. I think the prescribed method is to use newid() to set the value of a variable, then use that variable for any of your needs.|||Thanks. I figured as much, but wanted to check.|||One big selling point of GUIDs is that you don't need to return new values.
Your application can create the GUID value prior to submitting it for insert.|||a related point is the NEWSEQUENTIALID feature in 2005. if you have a guid column that forms a clustered pk, if you make its default NEWSEQUENTIALID, you won't get fragmentation the way you would if it was newid(). guids returned by this are guaranteed to be "bigger" than the last one returned.

however you still can't get the guid back by calling scope_identity() afaik.|||In SQL 2005 you can use the OUTPUT clause in your insert statement to return the generated id (if it is defined as default).

No comments:

Post a Comment