Name

INSERT

Synopsis

INSERT [LOW_PRIORITY|DELAYED|HIGH_PRIORITY] [IGNORE]
    [INTO] table
    SET column={expression|DEFAULT}, ...
    [ON DUPLICATE KEY UPDATE column=expression, ... ]
INSERT [LOW_PRIORITY|DELAYED|HIGH_PRIORITY] [IGNORE]
    [INTO] table [(column, ...)]
    VALUES ({expression|DEFAULT},...),(...),...
    [ON DUPLICATE KEY UPDATE column=expression, ... ]
INSERT [LOW_PRIORITY|DELAYED|HIGH_PRIORITY] [IGNORE]
    [INTO] table [(column, ...)]
    SELECT...

Use this statement to add rows of data to a table. Three statement structures are available. The first syntax format, the INSERT...tableSET... method, can insert only one row of data per statement. The second syntax structure shown, the INSERT...table(columns) VALUES(values) method, can handle one or more rows in one statement. The columns and their order are specified once, but values for multiple rows may be given. Each row of values is to be contained in its own set of parentheses, separated by commas. The third syntax structure for this statement, the INSERT...table...SELECT... method, allows columns from rows in other tables to be inserted. Explanations of each type of statement, their various clauses and flags, and examples of their use follow.

Single-row insertion with SET clause

INSERT [LOW_PRIORITY|DELAYED|HIGH_PRIORITY] [IGNORE]
    [INTO] table
    SET column={expression|DEFAULT}, ...
    [ON DUPLICATE KEY UPDATE column=expression, ... ]

This method of the INSERT statement allows only one row of data to be inserted into a table at a time. Each column name ...

Get MySQL in a Nutshell 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.