Create the orders Table

Learn to create another table with appropriate attributes and constraints.

We'll cover the following...

Introduction

We’ll continue the creation of our simple customer relationship management system. We already created the customers and products tables, and we’re now ready to create two more tables, orders and order_items.

Model details

The orders table holds the header of the order:

  • It has a reference to the owning customer by the customer_id column. This is going to be a foreign key. Given one order, we can locate the single customer that the order belongs to. That is why the order-to-customer relationship is a one-to-one relationship. On the other hand, given one specific customer, we can locate more than one order that belong to the particular customer. Hence, the customer-to-orders relationship is a one-to-many relationship.

  • Besides that, orders also have the order_number. This will be mandatory and will have a string representation like ORD123. It will also be ...