MySQL表中怎么一次插入两行或更多行
是的,我们可以一次在一个表中插入两行或更多行。以下是语法-
insert into yourTableName(yourColumnName1,yourColumnName2) values(yourValue1,yourValue2),(yourValue1,yourValue2),.........N;
让我们首先创建一个表-
mysql> create table DemoTable811( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (0.54 sec)
使用插入命令在表中插入多条记录-
mysql> insert into DemoTable811(StudentName,StudentAge) values('Chris',21),('Robert',22),('David',20),('Bob',19),('Carol',23);
Query OK, 5 rows affected (0.14 sec)
Records: 5 Duplicates: 0 Warnings: 0使用select语句显示表中的所有记录-
mysql> select *from DemoTable811;
这将产生以下输出-
+-----------+-------------+------------+ | StudentId | StudentName | StudentAge | +-----------+-------------+------------+ | 1 | Chris | 21 | | 2 | Robert | 22 | | 3 | David | 20 | | 4 | Bob | 19 | | 5 | Carol | 23 | +-----------+-------------+------------+ 5 rows in set (0.00 sec)
热门推荐
10 许嵩生日祝福语简短
11 奶奶生日感恩祝福语简短
12 城市祝福语简短10字
13 儿女的生日祝福语简短
14 给宝贝开学祝福语简短
15 简短祝福语大全暖心
16 生日祝福语 简短独特老弟
17 公司五一祝福语简短最新
18 异性朋友简短生日祝福语