RAND() vs NEWID() In SQL Server

Rand() vs NewId()

In my earlier articles, we have seen how to use RAND and NEWID. Now we will compare RAND() vs NEWID() and understand the major differences between them.

RAND() vs NEWID()

#RAND()NEWID()
1Used to generate random numbers.Used to generate GUID.
2Returns a pseudo random float value ranging between 0 and 1.Returns a value of type uniqueidentifier.
3Example value from RAND(): 0.713666525097956Example value from NEWID(): 52332A28-22B8-414D-8791-423EFFFDF9F1
4You can apply some formula and make it to return random integer or float between a range of numbers.You can CAST and then apply some formula and make it to return random integer or float between a range of numbers.
5Does not follow any specific standards.Follows RFC 4122 standards.

Reference


Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.