We are in an environment where, for several scenarios, it is required that rows in our database(s) have a GUID identifier (generated in app, not by the DB. The reason for this is because we are in a distributed/micro service environment).
Currently the GUID is a primary key.
These tables also have another integer (identity) identifier, which is unique and set as the clustered index. This is required as the default for SQL server is to have the PK as the clustered index, which is bad practice for GUIDs.
Given that there will always be a GUID, and there will always be a unique integer identifier, is there any disadvantage of having the integer identity column as the PK, and the GUID as a unique column?
Current:
- GUID (PK)
- INT (Unique, Clustered)
Proposed:
- INT (PK, Clustered Index (by default))
- GUID (Unique)
I've read up a bit on using GUIDs and what you need to be careful about. To speak generally, there seems to be disadvantages of the "Current" (GUID PK, INT unqiue/clustered). To my knowledge these would include:
- Performance
- Foreign keys/joins on GUIDS
- Large composite keys
- Size (tables with many FKs now have many GUID columns)
- Having to work with GUIDS at the SQL level (I.E. Debugging)
- Non standard*
What I mean by non-standard is that there is more to understand for developers and certain things you have to do/change when using a GUID approach to ensure it works well.
Again, to my knowledge, you don't get the above disadvantages when using the the "Proposed" (INT PK, GUID unique) approach, and I am surprised that this is not a more readily proposed solution, which leads me to think that there may be something that I am missing.
Given the requirements (there will always be two ways to unique identify a row, GUID and INT), is there any reason why you would not have the INT as the primary key?