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)
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)
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.
In the Navigation Pane, right-click the table to which you want to add the primary key, and click Design View. Tip: If you don't see the Navigation Pane, press F11 to display it. Locate the first available empty row in the table design grid. In the Data Type field, click the drop-down arrow and click AutoNumber.
No, it does not *have to be* autonumber.
Integer (number) data types are the best choice for primary key, followed by fixed-length character data types.
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).
This is a decision between surrogate and natural keys, the first being surrogate (or "technical") and the second being natural.
I've come to the conclusion that you should pretty much always use surrogate keys. If you use natural keys, those may change and updating primary/foreign keys is not generally a good idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With