Forum Moderators: phranque

Message Too Old, No Replies

Database design question

         

smagdy

9:15 am on May 7, 2005 (gmt 0)

10+ Year Member



Hi everybody...

Iam designing database that has categories for ex. like cars or mobiles.

so ive several categories like nokia, samsung, sony ericsson etc...

so there r lot of models in each category and every model have some info..

like nokia 9#*$! - size - weight - etc..

so my question is should i put every category (nokia, sony) in table
or all categories in one table?

Thanks in advance

john_k

11:10 am on May 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, you need to read up on relational database design. Here is a quick pass on some tables you would need:


CATEGORY
CategoryId
CategoryName
ParentCategoryId

ATTRIBUTE
AttributeId
AttributeName

ATTRIBUTEOPTION
AttributeOptionId
AttributeId
AttributeOptionName
PriceAmount
PricePercent
Weight

MANUFACTURER
ManufacturerId
ManufacturerName

ITEM
ItemId
ItemName
ManufacturerId
SKU
ManufacturerSKU
Weight

CATEGORYITEM
CategoryItemId
CategoryId
ItemId

ITEMATTRIBUTE
ItemAttributeId
ItemId
AttributetId

ITEMATTRIBUTEOPTION
ItemAttributeOptionId
ItemAttributeId
AttributeOptionId

So mobiles and cars would go into the Category table. Nokia, Ericsson, Samsung, and Sony would go into the Manufacturer table. Size goes into the Attribute table. Possible sizes go into the AttributeOption table. Sizes for a specific Item go into the ItemAttributeOption table. Weight goes into the Weight field of the Item table.

There are a hundred different ways to break down the smaller details. It all depends on what makes sense for your needs. If you have a lot of products and/or will be doing a lot of additions or updates, then you need to take time up front to get a good relational design. Otherwise the data maintenance will become extremely painful and expensive.

henry0

11:17 am on May 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you forecast many hundreds of items per cate
I will keep it simple (using PHP and MySQL)
have an auto incremented cat ID
then plug in all your cat
and when in need of a query you will do
... where id = $cat_id and cat=$cat or any query that allows for making use of a predefined cat and or ID

regards

Henry

smagdy

1:54 pm on May 7, 2005 (gmt 0)

10+ Year Member



Well, thanks for reply...

maybe i wasnt clear in something...

my database will just have one thing of mobiles or cars..

so lets say just mobiles..

so should i make

Category
id
name

Model
id
name
size
weight
etc...

OR

Nokia
model_name
size
weight
etc...

Sony_ericsson
model_name
size
weight
etc...

Samsung
model_name
size
weight
etc...

so one big table or several smaller ones maybe 10 max 20.

Thanks again

henry0

2:04 pm on May 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you are preparing for a VERY large number of items
I will use the first option