Database Normalization/Design

Database Normalization/Design

I have the following fields: productid, category.

A product can be in many categories, and a category can have many products. For example, product1 can be under category1 and category2. I don’t want to have to enter a duplicate entry for every new category.

Which is the most efficient way of designing the database? (I’m using MySQL.)

It seems that you have to accommodate a many-to-many relationship. Break these down into two one-to-many relationships.

You will need three tables to satisfy the problem:

  • Products[ProductID, ProductDescription]
  • Categories[CategoryID, CategoryDescription]
  • ProdCat[ProductID, CategoryID]

This will let you record your products in one table without repetition, record the categories in another table without repetition, and record the various connections between them in the ProdCat table. How you read the direction of the relation will reveal what products are in what categories as well as the other way round.

See also  5 Ways to Improve Customer Experience

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist