1

I would like to make my UserID column a GUID type and I found these three options. I do not know exactly what is the main difference between them.

Lili Prv
  • 11
  • 4
  • 1
    If you go with a GUID, `SCOPE_IDENTITY()` and `@@IDENTITY` are immediately out of question, they both deal with `IDENTITY` columns. – Alejandro Dec 10 '18 at 11:13
  • Also, take a look at the (broken) `OUTPUT` clause for retrieving the server-generated ID. – Alejandro Dec 10 '18 at 11:14

1 Answers1

1

I think the best version is NEWSEQUENTIALID().

->@@IDENTITY returns the last auto_incremented(identity) value (even if it is created by a trigger/user defined function).
->SCOPE_IDENTITY() returns the last identity value created (that is not created by a trigger or an udf).
->NEWSEQUENTIALID() creates a GUID that is greater than any GUID previously generated by this function on a specified computer since Windows was started. (For more information, see https://learn.microsoft.com/en-us/sql/t-sql/functions/newsequentialid-transact-sql?view=sql-server-2017)

Andrew Fan
  • 1,313
  • 5
  • 17
  • 29