如何插入具有分层类别的产品表
我有一个由相邻列表模型组成的表类别:
i have a table category made up of adjacent list model:
id name parent_id
1 Clothing 0
2 Books 0
3 Computers 0
4 Mobiles 0
5 Movies 0
6 Music 0
7 Mens 1
8 Shirts 7
9 Formal Trousers 7
10 Jeans 7
和product_category表:
and product_category table:
product_id fk
category_id fk
parent_id
并拥有产品表
product_id
category_id
parent_id
prod_name
genre
unit price
image
如何将表中的产品插入到与父ID相关联的表中,并将其链接到类别。以便我可以从parent_id和类别检索产品。
,我应该将parent_id定义为主键。
帮助赞赏...提前提交..
how can i insert the products in table that has link to the parent-id and in-turn it has link to category. so that i can retrieve the products from parent_id and categories. and should i define parent_id as a primary key.. help appreciated..thanks in advance..
如果我是正确的,我明白,您需要以相反的顺序检索数据。例如,parent_id + category_id - > product_id以及product_id - > parent_id + category_id。
If I am correct I understand that, you need to retrieve the data in reverse order. Such as, parent_id + category_id -> product_id as well as product_id -> parent_id + category_id.
希望你做得最多,我只是建议你使用SQL'其中'子句从结尾检索数据。
I hope you did the most, I just suggest you to use the SQL 'where' clause to retrieve the data from end.
我甚至想到在每个表中使用类别,父项和产品的PK,但经过一些研究,我发现我可以检索数据不改变数据库设计。
I even thought to use the PK of category, parent and product in each table but after some research I found I can retrieve the data without changing the database design.