Collection Table Database design __ Database

Source: Internet
Author: User
Product Collection features, how to design data tables
Product List Product ID, product name
Have user table

Now users can collect products, how to design data tables
1. Add the Favorites column in the user table to store it in a similar way (Product ID).
2. Or add a collection table, each user's collection as a piece of data.



It's a similar practice to create a separate collection table and basically not add favorites to the user table. Second, each user's one-time collection as a data record, daily records to have the user's number, Product ID

Add Favorites Table
1 2 3 4 5 6 7 Create TABLE Favorites table (id int identity (1,1) primary key, user ID int, product ID int, collection time datetime default (GETDATE ())


{User ID, Product ID, product name}

Product name is a redundant design, so when you need to show which products a user collects, simply query the Favorites table,
Instead of using cascading queries, query the user table and the Favorites table. 、

This is a good way to collect more products.
Method A suitable collection of products less than 30, at the same time extensibility is very limited, and the display needs to convert the string.

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.