Search⌘ K
AI Features

Insert Data into the orders Table

Explore how to insert new order data into the orders table using MySQL, including setting the current timestamp automatically and linking each order to a customer via foreign keys. Understand how to maintain data integrity and common pitfalls when inserting records.

Before we do anything else, let’s see our customers table:

MySQL
select * from customers;

Use of current_timestamp with insert

Now, we’re going to insert a new order in the orders table. We’ll use the following command:

insert into orders (order_number, ordered_at, customer_id) values ('ABC001', current_timestamp, 1);

Before we actually execute this command, let’s look at the new stuff here. Specifically, lets take a look at current_timestamp. This is used as a value for the ordered_at ...