The schema is normalized to the 3rd Normal Form (3NF) to eliminate redundancy and ensure data integrity. Each table has a primary key, and foreign keys are used to establish relationships between tables.
Core Entities
The main entities in an order management system are:
- Customers: Individuals or companies placing orders.
- Products: The items that can be ordered.
- Orders: The transaction itself, linking a customer to one or more products.
- Payments: Details about the payment for an order.
- Shipments: Information about the delivery of an order.
Database Schema
- Customers Table
CustomerID(Primary Key)FirstNameLastNameEmailPhoneCreatedAtUpdatedAt
- Addresses Table
AddressID(Primary Key)CustomerID(Foreign Key to Customers)AddressTypeStreetCityStateZipCodeCountryCreatedAtUpdatedAt
- Products Table
ProductID(Primary Key)ProductNameDescriptionCategoryId(Foreign Key to Categories)skuPriceStockQuantityCreatedAtUpdatedAt
- Orders Table
OrderID(Primary Key)CustomerID(Foreign Key to Customers)OrderDateStatus(e.g., Pending, Shipped, Delivered, Canceled))TotalAmountShippingAddressID(Foreign Key to Addresses)`BillingAddressID(Foreign Key to Addresses)`CreatedAtUpdatedAt
- OrderItems Table
A Junction table that links Orders and Products. An order can have multiple products, and a product can be part of multiple orders.
OrderItemID(Primary Key)OrderID(Foreign Key to Orders)ProductID(Foreign Key to Products)QuantityUnitPriceTotalPriceCreatedAtUpdatedAt
- Payments Table
Stores payment transactions related to an order.
PaymentID(Primary Key)OrderID(Foreign Key to Orders)PaymentDatePaymentMethod(e.g., Credit Card, PayPal, Bank Transfer)AmountStatus(e.g., Completed, Pending, Failed)
- Shipments Table
Tracks the shipping of items for an order. An order could potentially have multiple shipments.
-
ShipmentID(Primary Key) -OrderID(Foreign Key to Orders) -ShipmentDate-Carrier-TrackingNumber-Status(e.g., In Transit, Delivered, Returned)
Relationships
- Customers to Orders: One-to-Many (
Customers.customer_id→Orders.customer_id). A customer can have many orders, but an order belongs to one customer. - Customers to Addresses: One-to-Many (
Customers.customer_id→Addresses.customer_id). A customer can have multiple addresses. - Orders to OrderItems: One-to-Many (
Orders.order_id→OrderItems.order_id). An order can contain multiple items. - Products to OrderItems: One-to-Many (
Products.product_id→OrderItems.product_id). A product can be part of multiple order items. - Orders to Payments: One-to-Many (
Orders.order_id→Payments.order_id). An order can have multiple payment attempts or transactions. - Orders to Shipments: One-to-Many (
Orders.order_id→Shipments.order_id). An order can have multiple shipments. - Products to Categories: Many-to-One (
Products.category_id→Categories.category_id). A product belongs to one category, but a category can have multiple products.