MySQL查询快速插入多个记录
要快速插入多个记录,请使用单个INSERT并遵循以下语法-
insert into yourTableName values(yourValue1,yourValue2,...N),(yourValue1,yourValue2,...N).....N;
要了解上述语法,让我们创建一个表-
mysql> create table DemoTable2007 ( Amount1 int, Amount2 int, Amount3 int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2007 values(450,600,700),(1000,200,3000), (800,900,1200),(1300,1500,2000),(40000,50000,6700); Records: 5 Duplicates: 0 Warnings: 0
使用select语句显示表中的所有记录-
mysql> select * from DemoTable2007;
这将产生以下输出-
+---------+---------+---------+ | Amount1 | Amount2 | Amount3 | +---------+---------+---------+ | 450 | 600 | 700 | | 1000 | 200 | 3000 | | 800 | 900 | 1200 | | 1300 | 1500 | 2000 | | 40000 | 50000 | 6700 | +---------+---------+---------+ 5 rows in set (0.00 sec)