MySQL 批量insert 、單條insert
阿新 • • 發佈:2021-10-30
目錄
本文簡單介紹在MySQL中insert資料方法。
準備資料表
CREATE TABLE `test5` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, `age` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:yes, -1:no', PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
單條insert
單條insert:
mysql> insert into test5(name, age) values('Kirk', 12);
查詢結果
mysql> select * from test5;
+----+------+-----+
| id | name | age |
+----+------+-----+
| 1 | Kirk | 12 |
+----+------+-----+
1 rows in set (0.00 sec)
批量insert
批量insert:
insert into test5(name, age) values('Kim', 11), ('Sam', 12), ('Mark', 13);
查詢結果
mysql> select * from test5;
+----+------+-----+
| id | name | age |
+----+------+-----+
| 1 | Kirk | 12 |
| 2 | Kim | 11 |
| 3 | Sam | 12 |
| 4 | Mark | 13 |
+----+------+-----+
7 rows in set (0.00 sec)
以上,簡單介紹了 單條insert、批量insert的使用方法。
本文不在於介紹多複雜的知識點,而是以後使用時作為參考例子吧。
Just try, don't shy.