Search 
DailyCoding > Database

Generate New Guid (uniqueidentifier) in SQL Server

About how to generate a random unique identifier in using sql query in SQL server
Author admin on Jun 19, 2008 0 Comments
Rate it    (Rated 3 by 5 people)
815 Views

If you want to generate a new Guid (uniqueidentifier) in SQL server the you can simply use the NEWID() function.

Example

SELECT NEWID()
GO
-- This will return a new random uniqueidentifier e.g.
E75B92A3-3299-4407-A913-C5CA196B3CAB

You can directly use this with INSERT statement to insert new row in table.

-- Inserting data in Employees table.
INSERT INTO Employees
(EmployeeID, Name, Phone)
VALUES
(NEWID(), 'John Kris', '99-99999')
SQL

Discussion

Leave a Comment

Name
Email Address
Web Site
© Copyright 2008 Daily Coding • All rights reserved