Wednesday, November 08, 2006

Create a new GUID in SQL Server

To create a new uniqueidentifier or GUID (Globally Unique Identifier) in SQL Server use the newid() function:

select newid()

This function can be useful for creating test data but there is another use. It's also possible to select a random record using the script below:

select top 1 *
from dbo.Customer
order by newid()

I can't really think of any situation where this randomisation technique would have been helpful but, you never know !


Anonymous said...

Well I enjoyed it!

Anonymous said...

thats works!! cool..


Anonymous said...

cool ;)