What data type is recommended for ID columns?

后端 未结 9 1788
既然无缘
既然无缘 2021-02-08 04:35

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

9条回答
  •  轮回少年
    2021-02-08 05:14

    Tell me what criteria you think are important.

    What's required is to be unique within the table.

    A GUID is a global probabilistically-unique identifier. It's also big. If you need your indices to be unique to within epsilon over every other database installation in the universe, it's a good choice. Otherwise, it's using lots of space unnecessarily.

    An autoincrement number is good; it's small, and sure to be unique within the table. On the other hand, it gives you no protection against duplication; two entries, identical except for the magic number, are easy to create.

    Using some value that is tied to the entity being describes avoids that, but you have the problem of dealing with uniqueness.

提交回复
热议问题