How To Generate a New GUID In Sql Server

Simple:

SELECT NEWID()

So, why bother with this post?  Well, I spend most of time working within Visual Studio so whenever I think about creating a new GUID I automatically think:

System.Guid newGUID = System.Guid.NewGuid();

and then I realise that’s C#, then can’t remember if it’s

SELECT NEWGUID

or

SELECT GUID

in t-sql so I Google it and realise when I see an example that the code I am looking for is

SELECT NEWID()

.  Hence the post!

Leave a Reply

Your email address will not be published. Required fields are marked *