How to do a batch insert in MySQL

后端 未结 5 1764
离开以前
离开以前 2020-11-22 10:29

I have 1-many number of records that need to be entered into a table. What is the best way to do this in a query? Should I just make a loop and insert one record per itera

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 11:27

    From the MySQL manual

    INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example:

    INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
    

提交回复
热议问题