what is newid

Posted on : 30-06-2011 | By : Devi Prasad | In : SQL Server Basics

Share:

0


What is NEWID() ?

NEWID Creates a unique value of type uniqueidentifier.

Its return type is uniqueidentifier.

SELECT NEWID() 

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

CREATE TABLE #TEMPNEWID(COL1 int)

INSERT INTO #TEMPNEWID(COL1)
SELECT 1
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
UNION
SELECT 5
UNION
SELECT 6

SELECT COL1 FROM #tempnewid ORDER BY NEWID()

The above query will give values in table #TEMPNEWID ordered randomly.

(Visited 32 times, 1 visits today)



References : Devi Prasad (sqlserverlearner.com)

Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.


Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.




Write a comment