In my own understanding, shopping cart & amp; gt; user, 1-& amp; gt; 1 user & amp; gt; product information, n-& amp; gt; n: The shopping cart & amp; gt; item is n-& amp; gt; n. I don't know how to understand it? How should we design a database to associate these three elements? The method I have come up with is... in my own understanding,
Shopping Cart => User, 1-> 1
User => item information, n-> n
So:
Shopping Cart => goods are n-> n
I don't know. Is that correct?
How should we design a database to associate these three elements?
The method I have come up with is to create five tables:
- User table
- Item table
- Shopping Cart table
- User item Relationship table
- Shopping Cart item relation table
The main fields are:
- User table: id, uname, pwd, etc.
- Product table: id, goodname, price, etc.
- Shopping Cart table: id, uid, uid for the corresponding user id
- Shopping Cart item relation table: gid, cid respectively for item id, shopping cart id
- User item relation table: uid and gid are user IDs and item IDs respectively.
Can I design it like this? Is it efficient? Is there redundancy?
Recommend efficient database design... Thank you very much!
Reply content:
In my own understanding,
Shopping Cart => User, 1-> 1
User => item information, n-> n
So:
Shopping Cart => goods are n-> n
I don't know. Is that correct?
How should we design a database to associate these three elements?
The method I have come up with is to create five tables:
- User table
- Item table
- Shopping Cart table
- User item Relationship table
- Shopping Cart item relation table
The main fields are:
- User table: id, uname, pwd, etc.
- Product table: id, goodname, price, etc.
- Shopping Cart table: id, uid, uid for the corresponding user id
- Shopping Cart item relation table: gid, cid respectively for item id, shopping cart id
- User item relation table: uid and gid are user IDs and item IDs respectively.
Can I design it like this? Is it efficient? Is there redundancy?
Recommend efficient database design... Thank you very much!
First, you can directly convert the shopping cart concept into orders, which makes it easier to understand.A user places an order containing many items.In a simple sentence, the corresponding relationship is self-evident.
Therefore, four tables are created. The first three tables correspond to user information, order information, and commodity information respectively. The first three tables correspond to the order ID and commodity ID. If you query items frequently, you can add a table corresponding to the user ID and item ID.
Well... well, after writing it, you will find that the idea is the same as yours. It proves that this design is okay.
1. User table
2. Product table
3. Shopping Cart table (User id, product id, price and SKU information when added to the shopping cart)
4. Order table (User ID, order ID, suborder ID, order summary)
5. Order Details table (Order ID, suborder ID, product information when the order is generated)
I personally thinkUser item Relationship tableNo,Shopping Cart item relation tableOfgidAndcidCompositionprimary keyTo meetn->m. Regarding efficiency and standardization, this should meet the requirements of the paradigm. It is enough. For personal ignorance, if you have any questions, please discuss them.