0

I have an inventory with three numbered groups like so:

Group 1: 0-999 Group 2: e0-e999 Group 3: v0-v999

Can I simply make a one-column table to store this information and make that column the primary index (needed?), or should I make it two columns.

example:

code (primary)
000
016
760
433
e221
e011
v999
v003

vs.

(primary)
 code_id    code
    1        000
    2        016
    3        760
    4        433
    5        e221
    6        e011
    7        v999
    8        v003
0

You can use the one-column approach for simplicity. However, what happens when a code is changed? Will you have to update all related tables to have the new code?

Using an integer ID is the best choice for a primary key because it's small and efficient (strings have to be reduced/hashed to an integer before they are used as an index). Also, updating a code will happen in only one place and be reflected in all related tables automatically.

So I would recommend your second option for the sake of speed and to avoid a cascading update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.