Categories
Sql Server

Globally Unique Identifiers (GUID) In SQL Server

Globally Unique Identifiers (GUID) In SQL Server

In this post we will learn about Globally Unique Identifiers (GUID) In SQL Server.Globally unique numbers(GUID) data type actually holds information that is designed to be created and viewed using the standard 32-digit hexadecimal format.To generate such a value, the NewId() function is called.

Advantage:

  1. Unique across the server.

Disadvantage:

  1. String values are not as optimal as integer values for performance when used in joins, indexes and conditions.
  2. More storage space is required than INT.

Query:
SELECT NEWID()

--Create Table With Use Of GUID as Default--

CREATE TABLE Employee
(
EId int NOT NULL,
GId varchar(50) DEFAULT NEWID(),
EName varchar(40)
)

--Insert GUID Value--

INSERT Emp(EId,GId,EName)
VALUES (1,DEFAULT,'Jai')

INSERT Emp(EId,GId,EName)
VALUES (2,NEWID(),'Om')