I realize this question is very likely to have been asked before, but I've searched around a little among questions on StackOverflow, and I didn't really find an answer to mine, so here goes. If you find a duplicate, please link to it.
For some reason I prefer to use Guid
s (uniqueidentifier
in MsSql) for my primary key fields, but I really don't know why this would be better. In many of tutorials I've walked myself through lately an automatically incremented int
has been used. I can see pro's and cons with both:
- A
Guid
is always of the same size and length, and there is no reason to worry about running out of them, whereas there is a limit to how many records you could have before you'd run out of numbers that fit in anint
. int
is (at least in C#) a nullable type, which opens for a couple of shortcuts when querying for data.- And
int
is easier to read. - I bet you could come up with at least a couple of more things here.
So, as simple as the title says it: What is the recommended data type for ID (primary key) columns in a database?
EDIT: After recieving a couple of short answer, I must also add this follow-up question. Without it, your answer is neither compelling nor educating... ;) Why do you think so, and what are the cons of the other option that make you not choose that instead?