Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
CTEs with data modifying statements
6. INSERT statement


Alright, let's get started with CTEs with data modifying statements. First we will remember the syntax of INSERT statement. This statement is used to add data to the table. For example:

INSERT INTO grocery_store (id, name, city)
VALUES (9, 'Small Grocery Store', 'Washington');

The statement above inserts a new row into table grocery_store.

The statements starts with INSERT INTO, followed by the table name, and then the names of columns in brackets. Following these is the keyword VALUES, and in brackets: the list of values for the new row. Notice that names of columns and values are separated by commas. The values must be in exactly the same order as the column names.

There is also a shorter version of the INSERT statement if you set data into all of the columns in the table. Take a look:

INSERT INTO grocery_store 
VALUES (9, 'Small Grocery Store', 'Washington');

In this variation, you omit the list of column names and list only the values. In this case you must list the values in the exactly the same order in which the columns appear in the table.


We have a new customer: Anne Rogers from San Diego, who is 28 years old with id equal to 15 and discount equal to 0. Add her details to the database.

Stuck? Here's a hint!

Add data into customer table. Use INSERT INTO ... VALUES ...