Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
Thank you, you're right. I wasn't thinking it through. –  James Huckabone Jun 4 '13 at 16:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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