0

I have a situation where I am considering use of INT (Randomly generated) or GUID as the primary key of a table. I fully realize that a randomly generated INT could create a duplicate but I can easily deal with this and I am prepared to accept this so the chance of a duplicate is not part of the question.

Given that I am okay with the very very small chance of a duplicate INT.

Are there advantages or disadvantages to using INT vs GUID as the primary key or in indexes? Does SQL Server handle one or the other better when it comes to a range search? Does SQL Server have any optimizations for GUID vs INT?

Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427

1 Answers1

1

If you're concerned with performance, then int will beat out the GUID implementation simply because of the size of the data type. Are you comparing to using the uniqueidentifier type or using a char(32)? Either one will be slower than the int implementation.

GUIDs, however, are a good alternative depending on the type of application that you're building. If you are building something that you want to be able to generate a "unique" identifier prior to touching any state machine, then use GUID.

If you're a database guy, you may find yourself leaning towards an int.

If you're an application developer, you may find yourself leaning towards GUID.

Just a quick question, why not use a sequence?

It just depends.

Hope this helps.

square_particle
  • 526
  • 2
  • 7