Monodeep
Monodeep

Reputation: 1392

database schema confusion for category attributes

These are my requirements:

  1. Each Category has Multiple Groups
  2. Each group has multiple Attributes
  3. Each attribute has multiple values

So far i have come up with this DB Design

CategoryGroups Table

GroupID | CatID[References Category(CatID)] | GroupName

CategoryAttributes Table

AttributeID | AttributeName | GroupID[References CategoryGroups(GroupID)] | AttributeValue

So do you guys think this is a neat design?? Any suggestions??

Upvotes: 0

Views: 289

Answers (2)

emperorz
emperorz

Reputation: 427

Is there any reason not to have four tables for your four concepts?:

Category: id, <category stuff>
Group: id, category_id, <group stuff>
Attribute: id, group_id, <attribute stuff>
Value: id, attribute_id, <value stuff>

Primary keys are the id columns.

Foreign keys are as named (i.e. attribute_id is a foreign key to Attribute.id)

Upvotes: 0

Apart from naming your second table GroupAttributes, because it doesn't know anything about Category, this is one, most used, good approach. You have multiple 1:N (one to many) relationships, and you're referencing tables in the right way.

Upvotes: 1

Related Questions