Tuesday, March 3, 2020

Difference Between NEWSEQUENTIALID() and NEWID() in SQL Server

NEWSEQUENTIALID() and NEWID() both generates the GUID of datatype of uniqueidentifier.


NEWSEQUENTIALID:
  1. NEWSEQUENTIALID() generates GUID in hexadecimal incremental interval. The hexadecimal number can be any placed in GUID
  2. Function NEWSEQUENTIALID() can not be used in SQL queries and it can be only used in DEFAULT clause of table. NEWSEQUENTIALID() are predictable
  3. NEWSEQUENTIALID() generates the GUID in sequential order.

NEWID:

  • NEWID() generates the GUID in random order whereas 
  • in case of privacy or security use NEWID() instead of NEWSEQUENTIALID()
  • NEWID() will work perfectly fine when used in queries.


Table Syntax :

CREATE TABLE tablename
 (
 NewIDColumnName uniqueidentifier DEFAULT NEWID(),
 NewSeqColumnName uniqueidentifier DEFAULT NewSequentialID()
)

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...