Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:15:28+00:00 2026-06-18T03:15:28+00:00

I’m doing an e-commerce project and am confused about the database design for storing

  • 0

I’m doing an e-commerce project and am confused about the database design for storing products. There are 3 ways I’ve speculated the database can be made:

1.
There can be separate tables for each product category.

Table: Categories
------------------
cat_ID
cat_name

Table: Sub_Categories
---------------------
sub_cat_ID
categories_cat_ID
sub_cat_name

Table: Books
-------------
book_ID
sub_categories_sub_cat_ID
book_title
book_author
book_ISBN
book_price
etc

Table: Clothes
---------------
clothes_ID
sub_categories_sub_cat_ID
clothes_name
clothes_color
clothes_size
clothes_description
clothes_price
etc

Table: Perfumes
----------------
perfumes_ID
sub_categories_sub_cat_ID
perfume_name
perfume_size
perfume_weight
perfume_description
perfume_price
etc

2.
Group all products together in one table and allow some values to be null

Table: Categories
------------------
cat_ID
cat_name

Table: Sub_Categories
---------------------
sub_cat_ID
categories_cat_ID
sub_cat_name

Table: Products
---------------
product_ID
sub_categories_sub_cat_ID
title
description
price
author (can be null for everything except books)
size
weight (can be null for everything except perfumes)
ISBN (can be null for everything except books)
color (can be null for everything except clothes)
etc

3.
Group similar column fields together in a table called products, and provide separate tables for specific data.

Table: Categories
------------------
cat_ID
cat_name

Table: Sub_Categories
---------------------
sub_cat_ID
categories_cat_ID
sub_cat_name

Table: Products
----------------
product_ID
sub_categories_sub_cat_ID
title
description
price

Table: Books
-------------
products_product_id
sub_categories_sub_cat_ID
author
publisher
ISBN

Table: Perfumes
----------------
products_product_id
sub_categories_sub_cat_ID
size
weight

Table: Clothes
--------------
products_product_id
sub_categories_sub_cat_ID
color
size (this can be a one to many relationship to cater to multiple sizes of one product?)

I would really appreciate enlightenment, thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:15:29+00:00Added an answer on June 18, 2026 at 3:15 am

    I assume a product can belong to many categories, and a category (obviously) has many products in it. This relationship is called a many-to-many relation.

    In this instance, you would have three tables: categories, products, and categories_products. The first two tables are self-explanatory. The third table stores a relation between the two with two foreign keys. The tables would look like this:

    CREATE TABLE `categories` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `parent_id` int(10) unsigned DEFAULT NULL,
      `name` varchar(45) NOT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `name` (`name`),
      KEY `parent_id` (`parent_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    CREATE TABLE `categories_products` (
      `category_id` int(10) unsigned NOT NULL,
      `product_id` int(10) unsigned NOT NULL,
      KEY `category_id` (`category_id`),
      KEY `product_id` (`product_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    CREATE TABLE `products` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(45) NOT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `name` (`name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    ALTER TABLE `categories_products`
      ADD CONSTRAINT `categories_products_ibfk_2`
        FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
        ON DELETE CASCADE ON UPDATE CASCADE,
      ADD CONSTRAINT `categories_products_ibfk_1`
        FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
        ON DELETE CASCADE ON UPDATE CASCADE;
    

    Obviously these are the table schemas at their simplest. You will need to add your additional columns to the categories and products table—I’ve only included the columns relavant to the relation.

    EDIT: I also added a parent_id column to the categories table for nesting categories. It’s generally a bad idea to create a separate sub_categories table—what happens if you want to make a sub-category a top-level category? Or vice versa? You’re buggered for want of a better phrase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am confused How to use looping for Json response Array in another Array.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I've tracked down a weird MySQL problem to the two different ways I was
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.