{"id":28,"date":"2011-06-30T11:17:47","date_gmt":"2011-06-30T11:17:47","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2011\/06\/30\/what-is-newsequentialid\/"},"modified":"2011-06-30T11:17:47","modified_gmt":"2011-06-30T11:17:47","slug":"what-is-newsequentialid","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2011\/06\/30\/what-is-newsequentialid\/","title":{"rendered":"What is NEWSEQUENTIALID()"},"content":{"rendered":"

NEWSEQUENTIALID()<\/strong><\/p>\n

New NEWSEQUENTIALID generates new GUID.<\/p>\n

The GUID generated is always greater than GUID that was previously generated.<\/p>\n

Thus the new values inserted into tables using NEWSEQUENTIALID are in assending order and helps to fill index pages easyly.<\/p>\n

NEWSEQUENTIALID is faster in operation than NEWID.<\/p>\n

If a GUID Column in a table has to be bound with a unique Identifier then using NEWSEQUENTIALID is preferred.But the values can be predicted<\/strong><\/p>\n

NEWSEQUENTIALID cannot be used in queries like NEWID.<\/p>\n

[sql] SELECT NEWSEQUENTIALID() [\/sql]<\/p>\n

The above query would raise an error:<\/p>\n

The newsequentialid() built-in function can only be used in a DEFAULT expression for a column of type ‘uniqueidentifier’ in a CREATE TABLE or ALTER TABLE statement. It cannot be combined with other operators to form a complex scalar expression.<\/font><\/p>\n

Syntax for using NEWSEQUENTIALID with tables:
\n[sql]CREATE TABLE Table1 (Col1 uniqueidentifier DEFAULT NEWSEQUENTIALID()) [\/sql]<\/p>\n

How are values inserted into columns with NEWSEQUENTIALID?<\/strong><\/p>\n

[sql]CREATE TABLE Table1 (Col1 uniqueidentifier DEFAULT NEWSEQUENTIALID())
\nGO<\/p>\n

INSERT INTO Table1(Col1)
\nVALUES (DEFAULT)<\/p>\n

INSERT INTO Table1(Col1)
\nVALUES (DEFAULT)<\/p>\n

INSERT INTO Table1(Col1)
\nVALUES (DEFAULT)<\/p>\n

INSERT INTO Table1(Col1)
\nVALUES (DEFAULT)
\nGO<\/p>\n

SELECT * FROM TABLE1
\nGO[\/sql]<\/p>\n

The output of the above query will be something like this:
\n07D7AE4D-97A3-E011-B424-0021971FCF00
\n08D7AE4D-97A3-E011-B424-0021971FCF00
\n09D7AE4D-97A3-E011-B424-0021971FCF00
\n0AD7AE4D-97A3-E011-B424-0021971FCF00<\/p>\n

It can be seen that the values here are in sequence.<\/p>\n","protected":false},"excerpt":{"rendered":"

NEWSEQUENTIALID() New NEWSEQUENTIALID generates new GUID. The GUID generated is always greater than GUID that was previously generated. Thus the new values inserted into tables using NEWSEQUENTIALID are in assending order and helps to fill index pages easyly. NEWSEQUENTIALID is faster in operation than NEWID. If a GUID Column in a table has to be…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[89,90,91,92],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/28"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}