V
V
vladislav31012021-04-16 16:03:56
Database design
vladislav3101, 2021-04-16 16:03:56

How to properly store product orders in mysql database?

I read articles on the Internet about the architecture of the database and made such a database structure.
1. Product table - All product properties, name, price, etc.
2. Orders table - All customer data, order creation date, statuses (Cancelled, Accepted, Delivered, etc.)
3. Order_product table - product_id, order_id, count.
And so I started writing code and immediately ran into nuances. At the front, I store the cart data in an array, where each product is in the form of a json object when placing an order, I send the same array to the server, and I thought why do I need the "order_product" table if I can store the same array in the orders table and it will be fewer requests to the database. Tell me, if storing an array of products in the orders table is the right decision, or is it still to stick to articles from the Internet?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2021-04-16
@Rsa97

If your data is needed solely for storage in the database (written / read), then you can keep it in any form. If you need to work with them - perform search, aggregation, change - then it is correct to write them in a separate table and bring the database into normal form .

V
Vladimir Korotenko, 2021-04-16
@firedragon

Note an important point. At the time the order is formed, you must fix the price and description of the goods, and still keep a link to the original goods. Special fun if you have multi-currency payment. So normalization here seems to only hurt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question