How to Use GUID in Sql Server 2005?

Here is the sample code to use GUID (Globally Unique Identifier) in Sql Server 2005?

declare @x uniqueidentifier
set @x = newid()
select @x

declare @t table (id uniqueidentifier) -- Table Variable instead of using #temp table.

insert into @t values (newid())
insert into @t values (newid())
insert into @t values (newid())
insert into @t values (newid())
insert into @t values (newid())
insert into @t values (newid())

select * from @t

No comments: