CREATEtableMultipleRecordWithValues->(->idint,->namevarchar(100)->);QueryOK,0rowsaffected(0.88sec) The following is the syntax for batch insertion. INSERTintoyourTableNamevalues(column1,column2,....N"/> CREATEtableMultipleRecordWithValues->(->idint,->namevarchar(100)->);QueryOK,0rowsaffected(0.88sec) The following is the syntax for batch insertion. INSERTintoyourTableNamevalues(column1,column2,....N">
To do bulk insert, we need to use all column names with brackets and separated by ",".
Let's look at an example. First, we will create a table. Following is the CREATE command to create a table.
mysql> CREATE table MultipleRecordWithValues - > ( - > id int, - > name varchar(100) - > ); Query OK, 0 rows affected (0.88 sec)
The following is the syntax for batch insertion.
INSERT into yourTableName values(column1,column2,....N),(column1,column2,....N),(column1,column2,....N),...........N;
Apply the above syntax to insert batch records.
mysql> insert into MultipleRecordWithValues values(1,'John'),(2,'Carol'),(3,'Bob'),(4,'Smith'); Query OK, 4 rows affected (0.16 sec) Records: 4 Duplicates: 0 Warnings: 0
Since 4 rows are affected, this means we have successfully inserted the record. To check whether all records exist in the table, use the SELECT command.
mysql> select *from MultipleRecordWithValues;
The following is the output.
+------+-------+ | id | name | +------+-------+ | 1 | John | | 2 | Carol | | 3 | Bob | | 4 | Smith | +------+-------+ 4 rows in set (0.00 sec)
The above is the detailed content of How to do bulk insert in MySQL?. For more information, please follow other related articles on the PHP Chinese website!