Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jginorio's avatar

How to build a database schema for an inventory system with product stock, variation and attributes?

Background Information:

I'm trying to learn how to build an inventory tracking system for a sound company. I'm new to this and have no experience but I'm a fast learner, so please go easy on me. Before I start building the application, I want to make sure that I have the correct relational database design.

Design Requirements:

Each product has a stock that can be tracked individually (each stock has its own barcode) or bulk (stock has one barcode). Bulk tracking is mostly for cables because it's hard to put a barcode for each cable and scan each cable when it goes to an event.

Where I'm stuck on:

The product may have different variations. For example: "Cable Lenght", "Container Size", "Color", "Microphone Gain" and etc... The company can have the same cable in different lengths. Or have the same container in different sizes. Instead of creating a product for each length, I want to create a product variation.

In addition, each product may have different attributes. For example: "Frequency Band", "Serial Number", "Container Dimensions", "Firmware Version" and etc... A wireless microphone has attributes like Frequency Band, Firmware Version, and Serial Number. While there are products like containers that only have dimensions.

I already have a database design but I'm sure it is not correct and there can be a lot of improvements

Notes:

  • Not every product has a variation.
  • So far, if the product has a variation is only one type that applies to that product.
  • Not every product has all of the attributes. Some may only have Serial Number and some may have none.
  • The main reason for creating a variation, instead of an attribute, is because I want to track the quantity of each product variation.

Information:

Database design I have in mind https://drawsql.app/wsp/diagrams/wsp/embed

Populated products table https://i.stack.imgur.com/XlUOk.jpg

Populated stocks table https://i.stack.imgur.com/qtz9V.jpg

0 likes
1 reply
Tray2's avatar

Each product has and unique identifier.

  1. EAX1234
  2. EAX1235

So product 1. is a RCA Cable that is 50cm in length and gold platted

The product table

id: 1
name: The Name RCA Cable 50cm
manufaturer: Van den Hull
product_id: EAX1234
barcode: 122352

id: 2
name: The Name RCA Cable 100cm
manufaturer: Van den Hull
product_id: EAX1235
barcode: 122353

The product information table would look something like

product_id : 1
attribute: length
value: 50cm

product_id: 1
attribute: platting
value: gold

product_id: 2
attribute: length
value: 100cm

product_id: 2
attribute: platting
value: gold

The stock table

product_id: 1
quantity: 10

product_id: 2
quantity: 1

You could use a one to many in the stock table and have a record for each single product

product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 1
product_id: 2
product_id: 2
product_id: 2
product_id: 2
product_id: 2
product_id: 2

I would most likely go with the first option.

Please or to participate in this conversation.