Name
INSERT
Synopsis
INSERT [DELAYED | LOW_PRIORITY ] [INTO]table
[ (column
, ...) ] VALUES (values
) [,( values )... ] INSERT [LOW_PRIORITY] [INTO]table
[ (column
, ...) ] SELECT ... INSERT [LOW_PRIORITY] [INTO] table SET column=value, column=value,...
Inserts data into a table. The first form of this statement simply
inserts the given values into the given columns. Columns in the table
that are not given values are set to their default value or
NULL
. The second form takes the results of a
SELECT
query and inserts them into the table. The
third form is simply an alternate version of the first form that more
explicitly shows which columns correspond with which values. If the
DELAYED
modifier is present in the first form, all
incoming SELECT
statements will be given priority
over the insert, which will wait until the other activity has
finished before inserting the data. In a similar way, using the
LOW_PRIORITY
modifier with any form of
INSERT
will cause the insertion to be postponed
until all other operations from the client have been finished.
When using a SELECT
query with the
INSERT
statement, you cannot use the
ORDER BY
modifier with the
SELECT
statement. Also, you cannot insert into the
same table you are selecting from.
Starting with MySQL 3.22.5 it is possible to insert more than one row into a table at a time. This is done by adding additional value lists to the statement separated by commas.
You must have INSERT
privileges to use this
statement.
Examples
# Insert a record into ...
Get MySQL and mSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.