简体   繁体   中英

How are products stored in database?

I have a database to store different types of products for a shop. Do I keep record of every instance of the product? Or do I just decrease the quantity count every time a product is sold? I also want to store barcodes in the database. Is the barocde printed on the product unique to every instance? or is it just unique to product. For instance if I have 4 cans of Heinz Tomato soup, will they have same barcode value? If yes then how do I identify every instance uniquely? If no then how do I guarantee that the barcode value on the Heinz Tomato Soup can will not match barcode of any other product in a given shop?

Any help will be appreciated. Thank you. :D

You don't need a record for every instance of a product.

You should have an instance for a product with a stock quantity column for each record and work with the quantity field once a product gets sold or the stock gets replenished.

By definition the the barcode on the products is unique (not per instance) so you should be safe with it: Heinz Tomato Soup will have a code and Heinz Chicken Soup will have another one.

This might help you more: http://www.daveegerton.com/assets/images/database-schema-prestashop.png This is the database schema used by an eCommerce (Prestashop). Your questions answer is in the right bottom square the one in light brown :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM