Use item specific prefixes and autonumber for primary keys?

后端 未结 9 1470
孤街浪徒
孤街浪徒 2020-12-05 20:12

We had a meeting this morning about how would should store our ID for some assets that we have in our database that we are making, the descusion generated a bit of heat so I

9条回答
  •  盖世英雄少女心
    2020-12-05 20:40

    If your assets already have unique natural identifiers (such as employees with their employee IDs), use them. There's no point creating another unique identifier.

    On the other hand, if there's no natural unique ID, use the shortest one you can that'll ensure enough unique keys for your expected table size (such as your integer). It'll require less disk space and probably be faster. And, in addition, if you find yourself needing to use a string-based key later, it's a simple substitution job:

    • add sting primary key to asset table.
    • add string foreign key to referring tables.
    • update string relationships with simple UPDATE command using integer relationships.
    • add foreign key constraints for sting columns.
    • remove foreign key constraints for integer columns.
    • remove integer columns altogether.

    Some of these steps may be problematic on specific DBMS', perhaps requiring a table unload/reload to delete the integer primary key columns but that strategy is basically what's required.

提交回复
热议问题