Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat data type is recommended for ID columns?
    text
    copied!<p><em>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.</em></p> <p>For some reason I prefer to use <code>Guid</code>s (<code>uniqueidentifier</code> 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 <code>int</code> has been used. I can see pro's and cons with both:</p> <ul> <li>A <code>Guid</code> 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 an <code>int</code>.</li> <li><code>int</code> is (at least in C#) a nullable type, which opens for a couple of shortcuts when querying for data.</li> <li>And <code>int</code> is easier to read.</li> <li>I bet you could come up with at least a couple of more things here.</li> </ul> <p>So, as simple as the title says it: <strong>What is the recommended data type for ID (primary key) columns in a database?</strong></p> <p>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... ;) <strong>Why do you think so, and what are the cons of the other option that make you <em>not</em> choose that instead?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload