how can I use GUID datatype in SQL Server 2008?

前端 未结 7 2112
南旧
南旧 2021-02-18 22:15

I want to build an employees table using SQL SERVER 2008 , and in my table I want to have an ID for each employee .

I heared about GUID and

相关标签:
7条回答
  • 2021-02-18 22:18

    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

    0 讨论(0)
  • 2021-02-18 22:18

    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.

    0 讨论(0)
  • 2021-02-18 22:28

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

    0 讨论(0)
  • 2021-02-18 22:36

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

    Seriously: use a standard IDENTITY instead

    0 讨论(0)
  • 2021-02-18 22:40

    They are called uniqueidentifier

    0 讨论(0)
  • 2021-02-18 22:40

    The GUID in sql server is known by UNIQUEIDENTIFIER data type. below is the desired code.

     CREATE TABLE Employees 
        (
            Id UNIQUEIDENTIFIER PRIMARY KEY,
            Name NVARCHAR (50) not null
        )
        GO
    
    0 讨论(0)
提交回复
热议问题