示例
A.对变量使用 NEWID 函数
下面的示例使用 NEWID 对声明为 uniqueidentifier 数据类型的变量赋值。在测试该值前,将先打印 uniqueidentifier 数据类型变量的值。
-- Creating a local variable with DECLARE/SET syntax.
DECLARE @myid uniqueidentifier
SET @myid = NEWID()
PRINT 'Value of @myid is: '+ CONVERT(varchar(255), @myid)
下面是结果集:
Value of @myid is: 6F9619FF-8B86-D011-B42D-00C04FC964FF