Database Design: Why do some ecommerce database have separate tables for products and product_variants?
Why do some ecommerce database have tables:
- product
- product_variant
Why not only one product table w开发者_开发技巧ith all teh fields of product_variant and is_default_product(bool) field?
Thanks
This is called Slowly Changing Dimension
There are some approaches to implementing it which have their benefits and drawbacks.
Solution with two tables allows easier referencing to products (as opposed to product versions) from other tables.
If you have only one table, you have to modify your database design if you want to add product attributes. So if you are tracking colors and sizes in your table, and you want to add, say, inseam, you have to add a column to the table.
Keeping a separate table of attributes allows you to easily manage your attributes as entries in the table, rather than have them be a part of the actual design.
精彩评论