Insert the Wrong Customer Id
Learn how to avoid inconsistent data entry in the database.
We'll cover the following
Insert a nonexistent customer_id
Let’s see our customers and orders again.
mysql> select * from customers;
+----+-----------+----------+
| id | name | identity |
+----+-----------+----------+
| 1 | John Woo | JW0001 |
| 3 | Maria Moo | ML0001 |
+----+-----------+----------+
2 rows in set (0.00 sec)
mysql> select * from orders;
+----+--------------+---------------------+-------------+
| id | order_number | ordered_at | customer_id |
+----+--------------+---------------------+-------------+
| 1 | ABC001 | 2016-09-09 08:34:55 | 1 |
+----+--------------+---------------------+-------------+
1 row in set (0.00 sec)
The order with an id
of 1
refers to the customer with id
of 1
via the customer_id
column.
Let’s try to insert a new order that references a nonexistent customer. Try the following command:
Get hands-on with 1200+ tech skills courses.