I have a table Orders. Each order can have the same product multiple times. Quantity is not enough as each product may have different preferences!
So i am wondering what is better to do…
PK-id order id product id ? Primary key is PK-id
or
Orders Table
(Order-id ,orderline) as PK..
Then another table
Orderlines
(Order-id, orderline, productid) as PK
And then
OrderLinesPreferences
(Order-id ,orderline, productid, preferenceid )as PK ?
I wonder whether this approach is ok .Also i dont know what i should i do about indexing in order not to get slow when records are many. I am using postgresql..
For example in table OrderLinesPreferences a where order-id=1 and productid=10; would be fast or would do a full table lookup ?
Based on a comment made by @OP to an answer by dnuttle, I would say the situation calls for items and sub-items, all from a list of basic items.
So:
This gives you what you need to have an order with the same item multiple times and 0 or more options applied to each item, as in a coffee with different amounts of cream and sugar etc. as per OP’s requirement.