Reputation: 1314
I am building a database for a commercial store. I am debating the use of productID in the DB.
I also need to store the transaction history in the database.
Would it be better to use the productID, or use the barcode as a unique identifier for my products.
Upvotes: 0
Views: 709
Reputation: 52127
You basically have two options:
In the first case:
In the second case:
So it's basically a tradeoff between less or more JOINing and between "bottom-heavy" or "top-heavy" storage/caching. You just need to decide which fits better with your anticipated data access patterns...
1 I.e. tables that reference PRODUCT through FOREIGN KEY. A TRANSACTION_HISTORY might be an example of one such table.
Upvotes: 2
Reputation: 25534
You can use both can't you? No reason why products shouldn't have more than one type of identifier. Depending on circumstances however, a product could have more than one barcode. For retail packaged goods it's not uncommon to have multiple different barcodes for the same product.
Upvotes: 4
Reputation: 96600
Barcodes in general would be a bad PK. You would not want to join on them due to the datatype they would be stored as. Product Id is probably a better choice for any table that will have child tables. However, you should probably still put a unique index on the Barcode, nothing prevents more than one thing from having a unique index.
Upvotes: 2