Relationship Between shopping cart, user, and item table 3

Source: Internet
Author: User
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:

  1. User table
  2. Item table
  3. Shopping Cart table
  4. User item Relationship table
  5. Shopping Cart item relation table

The main fields are:

  1. User table: id, uname, pwd, etc.
  2. Product table: id, goodname, price, etc.
  3. Shopping Cart table: id, uid, uid for the corresponding user id
  4. Shopping Cart item relation table: gid, cid respectively for item id, shopping cart id
  5. 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:

  1. User table
  2. Item table
  3. Shopping Cart table
  4. User item Relationship table
  5. Shopping Cart item relation table

The main fields are:

  1. User table: id, uname, pwd, etc.
  2. Product table: id, goodname, price, etc.
  3. Shopping Cart table: id, uid, uid for the corresponding user id
  4. Shopping Cart item relation table: gid, cid respectively for item id, shopping cart id
  5. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.