快速插入多條記錄的 MySQL 查詢


如需快速插入多條記錄,請使用單 INSERT 並遵循以下語法 −

insert into yourTableName values(yourValue1,yourValue2,...N),(yourValue1,yourValue2,...N).....N;

為了理解以上語法,讓我們建立一個表 −

mysql> create table DemoTable2007
(
   Amount1 int,
   Amount2 int,
   Amount3 int
);
Query OK, 0 rows affected (1.36 sec)

使用 insert 命令在表中插入一些記錄 −

mysql> insert into DemoTable2007 values(450,600,700),(1000,200,3000),
   (800,900,1200),(1300,1500,2000),(40000,50000,6700);
Query OK, 5 rows affected (0.11 sec)
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)

更新日期: 02-1 月-2020

293 次瀏覽

啟動你的 職業

完成課程,獲得認證

開始
廣告
© . All rights reserved.