INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO] tbl_name { [(col_name, ...)] VALUES (expression, ...), ... | [(col_name, ...)] SELECT ... | SET col_name=expression, col_name=expression, ... }
The INSERT query is used to add new entries to a table. It supports three general options:
LOW_PRIORITY
The query will wait until there are no clients reading from the table before it proceeds.
DELAYED
The query completes immediately from the client's point of view, and the INSERT operation is performed in the background. This option is useful when you wish to insert a large number of rows without waiting for the operation to complete. Be aware that the client will not know the last inserted ID on an AUTO_INCREMENT column when a DELAYED insert is performed (e.g. mysql_insert_id in PHP will not work correctly).
IGNORE
Normally, when an inserted operation causes a clash in a PRIMARY KEY or UNIQUE column, the insert fails and produces an error message. This option allows the insert to fail silently—the new row is not inserted, but no error message is displayed.
The word INTO is entirely optional, and has no effect on the operation of the query.
As you can see above, INSERT queries may take three forms. The first form lets you insert one or more rows by specifying the values for the table columns in parentheses. If the optional list of column names is omitted, then the list(s) of column values must include a value for every column in the table, in the order in which they appear in the table.
In the second form of INSERT, the rows to be inserted result from a SELECT query. Again, if the list of column names is omitted, the result set of the SELECT must contain values for each and every column in the table, in the correct order. A SELECT query that makes up part of an insert statement may not contain an ORDER BY clause, and you cannot use the table into which you are inserting in the FROM clause.
The third and final form of INSERT can be used only to insert a single row, but it very intuitively allows you to assign values to the columns in that row by giving them in col_name=value format.
Columns to which you assign no value (e.g. if you leave them out of the column list) are assigned their default. By default, inserting a NULL value into a NOT NULL field will also cause that field to be set to its default value; however, if MySQL is configured with the DONT_USE_DEFAULT_FIELDS option enabled, such an INSERT operation will cause an error. For this reason, it‘s best to avoid them.