Results 1 to 6 of 6

Thread: a GUID question

  1. #1
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848

    Unanswered: 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?
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    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.

  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Thanks. I figured as much, but wanted to check.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    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.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    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.

  6. #6
    Join Date
    Mar 2005
    Location
    Netherlands
    Posts
    280
    In SQL 2005 you can use the OUTPUT clause in your insert statement to return the generated id (if it is defined as default).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •