When to use an auto-incremented primary key and when not to?

后端 未结 7 656
死守一世寂寞
死守一世寂寞 2020-12-13 01:39

I\'m trying to figure out the \"best practices\" for deciding whether or not to add an auto-incrementing integer as the primary key to a table.

Let\'s say I have a t

7条回答
  •  我在风中等你
    2020-12-13 02:25

    The main problem that I have seen with the auto incrementing an integer approach is when you export your data to bring into another db instance, or even an archive and restore operation. Because the integer has no relation to the data that it references, there is no way to determine if you have duplicates when restoring or adding data to an existing database. If you want no relationship between the data contained in the row and the PK, I would just use a guid. Not very user friendly to look at, but it solves the above problem.

提交回复
热议问题