Reasons not to use an auto-incrementing number for a primary key

前端 未结 16 2666
南旧
南旧 2020-12-29 06:02

I\'m currently working on someone else\'s database where the primary keys are generated via a lookup table which contains a list of table names and the last primary key used

16条回答
  •  一向
    一向 (楼主)
    2020-12-29 06:57

    Here's the thing with auto incrementing integers as keys:

    You HAVE to have posted the record before you get access to it. That means that until you have posted the record, you cannot, for example, prepare related records that will be stored in another table, or any one of a lot of other possible reasons why it might be useful to have access to the new record's unique id, before posting it.

    The above is my deciding factor, whether to go with one method, or the other.

提交回复
热议问题