Generating a New Guid (uniqueidentifier) in SQL Server Database.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 1105
If we want to generate a new Guid(uniqueidentifier) in SQL Server the we can simply use the NEWID() function.

For Example

SELECT NEWID()


-- This will return a new random uniqueidentifier as
E75B92A3-3299-4407-A913-C5CA196B3CAB


To select this Guid in in a variable

--assign uniqueidentifier in a variable
DECLARE @EmployeeID uniqueidentifier
SET @EmployeeID = NEWID()

Comments or Responses

Login to post response