MySQL INSERT Statement
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.
INSERT INTO sakila.actor (first_name, last_name)
VALUES ('Homer', 'Flinstone');
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:
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:
INSERT INTO sakila.actor
VALUES (202, 'Fred', 'Simpson', '2015-06-20 14:00:00');
Follow that up with a SELECT statement and here's the result:
Insert Multiple Records
You can insert multiple rows by using a comma to separate the values. Like this:
INSERT INTO sakila.actor (first_name, last_name)
VALUES
('Barney', 'Flinstone'),
('Marge', 'Rubble'),
('Bart', 'Griffin');
Here's the result:
The examples on this page use the Sakila sample database.