how can I use GUID datatype in SQL Server 2008?

穿精又带淫゛_ 提交于 2019-12-04 00:49:53

It's not called GUID in SQL Server. It's called uniqueidentifier

The type is called UNIQUEIDENTIFIER as others have pointed out already. But I think you absolutely must read this article before proceeding: GUIDs as PRIMARY KEYs and/or the clustering key

They are called uniqueidentifier

Don't use uniqueidentifier as primary key if clustered (which is the default for PKs)

Seriously: use a standard IDENTITY instead

Practical demo, FWIW

DECLARE @guid1 AS uniqueidentifier
SET @guid1 = NEWID()
SELECT @guid1

You can also consider using NEWSEQUENCIALID as the default value for your ID column as it would be faster than using NEWID() generate the GUIDs.

BUT (from the same link above):-

If privacy is a concern, do not use this function. It is possible to guess the value of the next generated GUID and, therefore, access data associated with that GUID.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!