{"id":27,"date":"2011-06-30T10:45:42","date_gmt":"2011-06-30T10:45:42","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2011\/06\/30\/what-is-newid\/"},"modified":"2011-06-30T10:45:42","modified_gmt":"2011-06-30T10:45:42","slug":"what-is-newid","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2011\/06\/30\/what-is-newid\/","title":{"rendered":"what is newid"},"content":{"rendered":"

What is NEWID() ?<\/strong><\/p>\n

NEWID Creates a unique value of type uniqueidentifier.<\/p>\n

Its return type is uniqueidentifier.<\/p>\n

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

The output of the above query will be a unique identifier, some value like 8845D456-56FF-445Y-DF49-7GGTY54D3E3E<\/strong><\/em><\/p>\n

NewID can also be used to sort the rows in randomly as shown below<\/p>\n

[sql]CREATE TABLE #TEMPNEWID(COL1 int)<\/p>\n

INSERT INTO #TEMPNEWID(COL1)
\nSELECT 1
\nUNION
\nSELECT 2
\nUNION
\nSELECT 3
\nUNION
\nSELECT 4
\nUNION
\nSELECT 5
\nUNION
\nSELECT 6<\/p>\n

SELECT COL1 FROM #tempnewid ORDER BY NEWID()[\/sql]<\/p>\n

The above query will give values in table #TEMPNEWID ordered randomly.<\/p>\n","protected":false},"excerpt":{"rendered":"

What is NEWID() ? NEWID Creates a unique value of type uniqueidentifier. Its return type is uniqueidentifier. [sql]SELECT NEWID() [\/sql] The output of the above query will be a unique identifier, some value like 8845D456-56FF-445Y-DF49-7GGTY54D3E3E NewID can also be used to sort the rows in randomly as shown below [sql]CREATE TABLE #TEMPNEWID(COL1 int) INSERT INTO…<\/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":[],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/27"}],"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=27"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}