Use item specific prefixes and autonumber for primary keys?

database-design, primary-key

Solution

Usually the rule of thumb is that never use meaningful information in primary keys (like Social Security number or barcode). Just plain autoincremented integer. However constant the data seems - it may change at one point (new legislation comes and all SSNs are recalculated).

Problem

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 decided to consult the experts of SO. The table structure that I belive that we should have(short version) is like the following: Example 1) - AssetId - int(32) - Primary Key - Type - string so some example data is like this: ``` ==AssetId======Type=== 12345 "Manhole" 155415 "Pit" ``` etc. Another member of the team suggested something like this: Example 2) - AssetId - string - Primary Key - Type - string so some example data is like this: ``` ==AssetId======Type=== "MH12345" "Manhole" "P155415" "Pit" ``` where we make a short version of the type and append it to the front of the ID and store it in the database. I have seen a few asset databases that do this and have never really this approach. I have never really liked the idea of using strings as ID for sorting reasons. I also feel like it is storing useless information just for the sake of it when you already have the type of asset store anyway. What approach would you take? And why? Are there any benefits to using approach 1 over 2? EDIT: Yes I will be using AUTO_INCREMENT for approach 1.

Original source