7

I am new to database design. I am designing a database for an E-commerce website, there are a lot of products to be updated, but while designing for product specification table I do not understand whether I need specify all the specifications in a table or do I need to use different tables for different products?

For example, consider the products Mobile and book, each of these having unique specifications (such as color,size, cost, model for mobile and title, ISBN, author, cost, year_of_publication, etc. for book), if it is only less number of products then it is possible for me to design, but when there is a thousands of products, it takes a lot of time.

Can anyone tell me how to design my database to manage this situation?

5

If you know most of the attributes your products will have ahead of time, you could hard-code them into the tables for different product types, such as:


books
-----
  id
  price
  title
  author
  isbn
  etc....

mobile_device
-------------
  id
  price
  size
  colour
  model
  etc...

You could also try something like this:


base_product
------------
  id
  base_price
  product_type

book_product_attributes
-----------------------
  base_product_id (FK to base_product)
  title
  author

mobile_dev_product_attributes
-----------------------------
  base_product_id (FK to base_product)
  model
  colour

This way, you can group your common attributes in a base product table, and more specific attributes are stored in other tables when necessary.

This will work if your product types are mostly static. On the other hand, if you have no idea what product types or attributes you'll need in the future, and entity-attribute-value based system might work better. The idea behind that model is that you have a table for the different attributes you might have, a table for the different entities in your system, and a table for the attribute values that an entity has. Example:

entities
--------
  id

attributes
----------
  id
  name

values
------
  id
  entity_id
  attribute_id
  value

The data might look like this:


entities
ID
----
  1

attributes
ID |  name   
----------
1  |  title
2  |  author


values
ID  | attribute_id   | entity_id   | value
---------------------------------------------------------
1   | 1              | 1           | "Great Expectations"
2   | 2              | 1           | "Charles Dickens"

This data very briefly describes a product which has two attributes: title, and author, with the valus "Great Expectations" and "Charles Dickens", respectively.

Be aware that using an EAV database can make queries very awkward. With enough data and the wrong model design, it's also possible to run into performance problems. The example I gave was very simple but more realistic designs tend to be more complicated than that. It can take time to get this kind of database correct and it's not always the best solution.

  • Hi, thank you for your time, as I am new to DBA I can get some understanding from your lines...sorry for my English. – rathishDBA Mar 13 '13 at 12:09
2

I will provide you the design details based on my experience..

Analysis part....we are talking about products and its specifications. Product entity contains all the products information like car,mobile,book etc. specification entity contains all the specifications like color,size,model,cost,title etc. Here each product contains many specifications and each specification is belongs to one or many products.There is a many to many relationship between the entities Products and its specifications.In physical database level, you can find three basic tables namely.. PRODUCT,SPECIFICATION,PRODUCT_SPECIFICATION..................................

PRODUCT -->Product id(PK),Product name,Description

SPECIFICATION --> Specification id(PK),Specification Name,Description

PRODUCT_SPECIFICATION --->Product id(PK), Specification id(PK), prod_spec_Value

We can extend this design based on the requirements.

Regards, Bharath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.