Inserting Data Using INSERT

The INSERT statement is the primary way of getting data into a database. It takes the following format:

INSERT [LOW PRIORITY | DELAYED] [IGNORE]
  [INTO] table_name
  SET column_name1=expression1, column_name2=expression2,...

or

INSERT [LOW PRIORITY | DELAYED] [IGNORE]
  [INTO] table_name [(column_name,...)]
  VALUES (expression,...),(...)...

or

INSERT [LOW PRIORITY | DELAYED] [IGNORE]
  [INTO] table_name [(column_name,...)]
  SELECT...

The first form is a the most verbose but is in many cases the most convenient because the SET... explicitly names each column and states what value (evaluated from each expression) should be put into it.

Here's an example that adds a row of data to the subscribers table of a content management ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition 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.