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.