• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1248
  • Last Modified:

Datatype: uniqueidentifier or bigint as primarykey?

Uniqueidentifier or bigint as primarykey? Which is better to use as a primary key?

Using uniqueidentifier you will be given a global uniqueidentifier
but this also means the value will be very large! larger than bigint!
16 bytes vs 4 bytes!!!

is it really important?
0
Khou
Asked:
Khou
4 Solutions
 
sujith80Commented:
I dont think it makes any considerable difference, as long as you dont have a composite primary key.
0
 
Cedric_DCommented:
From my point of view, it makes difference for  large tables.
Redundant 12 bytes could be at cost, because as PK it will involved in all seek operations.

Another reason: you cannot make guid autoincrement (by IDENTITY(1,1)).

The only huge benefit of guid is really multy-server environment, to provide uniqueness.




0
 
dportasCommented:
Depends what you are going to use it for. You haven't given us much clue because "primary key" actually says very little about how it will be used. Do you mean that you intend to use it only as a surrogate key?
0
 
KhouAuthor Commented:
@dportas
" Do you mean that you intend to use it only as a surrogate key?"

Yes,

At the end of the day, I decided to Unquieidentifier , with newsequecialid().

Reason: GUID for replication, newsequeicailid() for performance.
still not as fast as int, but will do.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now