Insert Necessary Data
Learn to insert data into tables.
We’ll now execute the following commands to create the necessary data to support our query exercises.
First, we create the customers
:
Press + to interact
insert into customers (name, identity) values ('John Woo', 'JW001');insert into customers (name, identity) values ('Maria Foo', 'MF001');insert into customers (name, identity) values ('Jim Papas', 'JP001');insert into customers (name, identity) values ('Jessy Romeo', 'JR001');insert into customers (name, identity) values ('Arya Stark', 'AS001');
We get a Succeeded
response, which means the queries executed successfully and there’s nothing to show.
If we select the customers
, we should see this:
mysql> select * from customers;
+----+-------------+----------+
| id | name | identity |
+----+-------------+----------+
| 4 | John Woo | JW001 |
| 5 | Maria Foo | MF001 |
| 6 | Jim Papas | JP001 |
| 7 | Jessy Romeo | JR001 |
| 8 | Arya Stark | AS001 |
+----+-------------+----------+
5 rows in set (0.00 sec)
Click “Run” to verify the result:
Press + to interact
select * from customers;
The first customer’s order
Then, create orders and order items. Insert one order with one order item for the first customer:
mysql> insert into orders (order_number, ordered_at, customer_id) values ('ABC001', current_timestamp, 4);
Query OK
mysql> select * from orders;
+----+--------------+---------------------+-------------+
| id | order_number | ordered_at | customer_id |
+----+--------------+---------------------+-------------+
| 2 | ABC001 | 2016-09-12 21:36:56 | 4
...Access this course and 1400+ top-rated courses and projects.