Design a table for several different products on one order

If I had an online shopping site that sold apples and monitors, and they were stored in different tables, because the distinguishing feature of apples is color, and the color of monitors is permission, how would I add this data to the table of accounts while maintaining link integrity and without combining these tables?

                        Invoices(InvoiceId)
                                 |
                  InvoiceItems(ItemId, ProductId)
                                 |
                       Products(ProductId)
              |                                            |
Apples(AppleId, ProductId, Colour)   Monitors(MonitorId, ProductId, Resolution)
+3
source share
4 answers

First, I would save them in one Products table, and not in two different tables.

Secondly, (if only each account was intended for only one product), I would not add them to one table of accounts, instead I would set the Invoice_Products table to link between the tables.

.

+3

. , ? SKU?

, SKU. . SKU . - :

product {sku} key {sku};

invoice_item {invoice_id, sku} key {invoice_id, sku};

apple {color, sku} key {color} key {sku};

monitor {size, sku} key {size} key {sku};

... , apple {sku} monitor {sku} == product {sku}.

+1

Invoice ProductID FK, ProductID AppleID ( PK), MonitorID ( PK)?

, ProductTypeID , 0 = apple, 1 = monitor isProductTypeApple boolean, - 2 , ProductID PK.

ProductTypeID Apple Monitor PK.

0

... , , "", " "... , , . ( ).

... "product_type", , ( ), "product_id", apple/ . ​​ sql... , , ( , , )

, ... db , , .

0

Source: https://habr.com/ru/post/1768439/


All Articles