8.3.08

Unique Identifier in sql server

Unique identifier is used to create an unique 32 bit column value in the table. NewID() is a system function used to generate unique identifier value. It will take millions of years to generate a duplicate Unique identifier value
I am using NewID() to insert the data,
Code Snippet

DECLARE @VenkatTableVar table
( RowGUID uniqueidentifier PRIMARY KEY,VenkatName sysname,Name varchar(20))


INSERT INTO @VenkatTableVar1
VALUES (newid(),'Venkat','VenkatName')


SELECT * FROM @VenkatTableVar

Tried with manual data into the unique identifier column,
Code Snippet

DECLARE @VenkatTableVar table
( RowGUID uniqueidentifier PRIMARY KEY,VenkatName sysname,Name varchar(20))


INSERT INTO @VenkatTableVar
VALUES ( cast( 'A8FB1E48-F129-44RC-82AE-001EAD5A8ADE' AS binary ), 'Venkat','VenkatName')


SELECT * FROM @VenkatTableVar

No comments:

Post a Comment