laura1707
laura1707

Reputation: 9

Database for online shop with many products

How do I create a database which contains many different products of various categories? They also have different attributes.

My idea is to create 3 tables:

Product (pid)

Category (cid, parentcategory)

Product_category (pid, cid)

I think this manages the categories, but how do i store the attributes efficiently?

Upvotes: 0

Views: 316

Answers (1)

madaimartin
madaimartin

Reputation: 99

If your products will not be in two or more categories, you don't need conenction table. According to the comment section, I have a suggestion for you:

If and only if you decide to store category and sub_category then you have to implement it like this:

category(id, name)
sub_category(id, name, category_id)
product(id, name, sub_category_id)

With this method every products are aware of what is their subcategory. If we have the subcategory, then we are also able to determine the (main) category of every product.

I hope I could help you. Designing the scheme of the database is a very important step of developing an application.

Upvotes: 0

Related Questions