How to Generate New Guid (unique identifier) in SQL Server

New Guid (unique identifier) in SQL Server

GUID (Global Unique Identifier) is one of the good concept in SQL Server. In most of the places we will use the GUID.

Examples to use GUID in Sql server:

1. Create new GUID: below SQL statement will create the GUID.

select NEWID() [New GUID] 

2. GUID in a variable: Below statement will print the new guid. we will use these variable guid's in the stored procedures, functions, triggers and others.

DECLARE @EmpID uniqueidentifier
Print @EmpID 

3. GUID in a new row: In the below SQL Statement, we are using GUID for creating a table column and inserting values into tables.

 create table empExample (eid uniqueidentifier, ename varchar(40), 
salary numeric)
 insert into empExample values(NEWID(),'Ranga Rajesh', 900000) 

Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar