Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GUID as PK or as index only?

We want to have our client apps to be able to generate identifiers for objects they create.

We have 2 options to implement that:

  1. Have GUID (generated by client) as PK, non-clustered and at the same time have AUTO_INCREMENT int column with clustered index on it for later, under the hood usage mainly in JOINS
  2. Abandon AUTO_INCREMENT column completely

We are not worried about storage space.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there any significant gain going with option 1, or in other words, anything problematic with option 2?

>Solution :

For your requirement:

We want to have our client apps to be able to generate identifiers for objects they create.

I would suggest you have a regular int/bigint identity column primary key as this typically performs better than a uniqueidentifier.

And then add a surrogate GUID (uniqueidentifier) column, which would be indexed as a unique, non-clustered index.

This gives you the best of both worlds. A well performing primary key, and the ability to assign identifiers to your objects client side.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading