MySQL INSERT Statement

The INSERT statement is used to insert data into a database table. When using the INSERT statement, you specify the table name and the values that need to be inserted.

The above statement inserts "Homer Flinstone" into the actor table in the sakila database. "Homer" goes into the first_name column, "Flinstone" goes into the last_name column.

After running the above script, if we then run a SELECT statement against the table, we can see the new record has been inserted:

Screenshot of results

Variation

You can also use the INSERT statement without specifying the column names. In this case, you need to provide a value for each column, in the order that they are listed in the database. Like this:

Follow that up with a SELECT statement and here's the result:

Screenshot of results

Insert Multiple Records

You can insert multiple rows by using a comma to separate the values. Like this:

Here's the result:

Screenshot of results

The examples on this page use the Sakila sample database.