How do you design a schema for a feature like orders and products?

SQL keys and table design · Experienced

Model answer

Customers, products, orders and order_items tables. order_items stores order_id, product_id, quantity and the unit price at purchase time (prices change later, so copy it), with foreign keys and constraints. Money in DECIMAL, timestamps in UTC, and indexes on foreign keys.

Learn this topic

Keys and Table Design: Why Data Is Split Into Tables in the course SQL for Beginners: Learn Databases Step by Step.

Sign in to add your own answer.

More questions