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?

1

3 Answers 3

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.

1
  • Hi, thank you for your time, as I am new to DBA I can get some understanding from your lines...sorry for my English. Commented Mar 13, 2013 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

1
0

Shopify basiscally exposes their database structure from their dev portal: https://shopify.dev/docs/api/admin-rest/2023-10/resources/product

If you click on "Product", "ProductImage", "Collection", "Order" you can start to see how the models should be built and how the relationships work together between the models.

The order page (https://shopify.dev/docs/api/admin-rest/2023-10/resources/order) even shows diagrams of how the relationships work.

Shopify uses "Metafields" to give you the power to flexibly personalise product information, for books, power tools etc (https://shopify.dev/docs/api/admin-rest/2023-10/resources/metafield)

As one of the biggest eCommerce providers online, it would be a great place to start before you customise it to your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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