You are here

16 May 2018

To insert multiple rows with a single query you can use regular insert with multiple value rows. You can also use update if you have primary key set.

Source code viewer
  1. /* Table and column names.*/
  2. INSERT INTO my_table (column_1, column_2)
  3. /* Rows to insert. */
  4. (0, 'Value 1'),
  5. (1, 'Value 2'),
  6. (2, 'Value 3'),
  7. (3, 'Value 4'),
  8. (4, 'Value 5')
  9. /* When the primary key exists, update the value. */
  10. colum_2 = VALUES(column_2),
  11. ...
Programming Language: MySQL