MySQL中如何同时输入多个数据?
mysqlmysqli database
以下是语法 −
insert into yourTableName values(yourValue1,yourValue2,.....N), (yourValue1,yourValue2,.....N), (yourValue1,yourValue2,.....N), (yourValue1,yourValue2,.....N), . . . N
让我们创建一个表 −
mysql> create table demo56 −> ( −> id int, −> first_name varchar(20), −> last_name varchar(20), −> age int −> ); Query OK, 0 rows affected (1.91 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into demo56 values(1,'John','Smith',23), −> (2,'David','Miller',21), −> (3,'Chris','Brown',22), −> (4,'Carol','Taylor',20); Query OK, 4 rows affected (0.10 sec) Records: 4 Duplicates: 0 Warnings: 0
使用 select 语句显示表中的记录 −
mysql> select *from demo56;
这将产生以下输出 −
+------+------------+-----------+------+ | id | first_name | last_name | age | +------+------------+-----------+------+ | 1 | John | Smith | 23 | | 2 | David | Miller | 21 | | 3 | Chris | Brown | 22 | | 4 | Carol | Taylor | 20 | +------+------------+-----------+------+ 4 rows in set (0.00 sec)