# Inventory Database Design

Learn how to design an inventory database: core tables and fields, primary keys, a sample schema, MySQL tips and how to track stock across warehouses.

Inventory database design means choosing the tables, fields and links that record each item you stock. A good design keeps product details, stock levels and storage locations in separate places that connect cleanly. Below you will find a sample schema, the job of primary keys and notes for MySQL. The same structure suits a stock database for a small shop or a full inventory management system. 

## Core tables of an inventory schema 

An inventory database schema rests on a few core tables, each describing one kind of thing. A products table holds the name, description and SKU, short for stock keeping unit, of every item. A locations table lists warehouses, rooms or shelves, while a stock table records quantities per location. A movements table logs every receipt, sale and transfer, giving you a history behind each count. 

## Primary keys and links between tables 

Primary keys give every row in an inventory database a unique identifier that should stay fixed. A foreign key is a field that points to the primary key of another table. The stock table, for example, stores a product ID and a location ID instead of copying names. Storing each fact once means a renamed product updates everywhere without editing many rows. 

## Setting up the design in MySQL 

MySQL suits inventory management database design because it supports foreign keys through its InnoDB storage engine. An auto-increment integer column works well as the primary key for each table. Quantities belong in an integer or decimal column, depending on whether items can be split. Adding indexes on product and location IDs speeds up the lookups an inventory system runs constantly. 

## Inventory database design questions 

### What does an inventory database schema example look like? 

An inventory database schema example can be as simple as four linked tables. Products holds the product ID, SKU, name and price, while locations holds the location ID and name. Stock joins them with product ID, location ID and quantity on hand. Movements records product ID, location ID, change in quantity, type and timestamp for each event. 

### How do you design a database for warehouse inventory? 

Warehouse inventory database design adds a location hierarchy, such as warehouse, aisle, shelf and bin. Each location row can store a parent location ID, which lets one table describe every level. Stock is then recorded against the smallest location, such as a single bin. Transfers between bins appear as two movement rows, one leaving and one arriving. 

### Should stock levels be stored or calculated from movements? 

Stock levels can be stored in a table or calculated from movements, with a trade-off either way. Calculating from the movements table keeps one source of truth but slows down large reports. A stored quantity reads quickly, yet it must update in the same transaction as each movement. Comparing the stored quantity with the movement history from time to time catches mismatched counts. 

### How do you add custom fields to a product inventory database? 

Custom fields in a product inventory database can live in a separate attributes table. Each attribute row holds a product ID, a field name and a value, such as shape or length. Adding a new field then needs no change to the products table itself. MySQL also offers a JSON column type for storing flexible attributes on the product row.
