I am trying to make a data model for orders where in one order, I can have many products. So far I came up with this model:
The idea is that one order can produce many rows in order_product table(I have the name and price attributes, since they might get updated later in time and I want to keep the values that were correct at the time of the order creation (and I am also missing PRODUCT_ID foreign key since I don't really need it.)). My questions are:
- Is this approach correct?
- How can I manage the inserts in this way if the approach is correct - I first make a record for an order, then I insert all the products in the order_product table using the ID of the order I first made, but how do I get the ORDER_ID required for the order product table?
I am really new to SQL so excuse me if the question is anyhow dumb. I just really struggle to find a proper way of doing this. Thanks in advance.