SQL Server - Guid VS. Long

后端 未结 7 1849
野的像风
野的像风 2020-12-29 00:06

Up until now i\'ve been using the C# \"Guid = Guid.NewGuid();\" method to generate a unique ID that can be stored as the ID field in some of my SQL Server database tables us

7条回答
  •  不知归路
    2020-12-29 01:01

    A long (big int in sql server) is 8 bytes and a Guid is 16 bytes, so you are halving the number of the bytes sql server has to compare when doing a look up.

    For generating a long, use IDENTITY(1,1) when you create the field in the database.

    so either using create table or alter table:

    Field_NAME BIGINT NOT NULL PRIMARY KEY IDENTITY(1,1)
    

    See comments for posting Linq to sql

提交回复
热议问题