如何通过单个INSERT在MySQL表中插入值数组?

让我们首先创建一个表-

create table DemoTable
(
   ClientId int,
   ClientName varchar(50)
);

使用insert命令在表中插入一些记录。在这里,我们仅使用单个INSERT插入多个值-

insert into DemoTable values(101,'Adam'),(102,'Chris'),(103,'Robert'),(104,'Sam'),(105,'Mike');
Records: 5 Duplicates: 0 Warnings: 0

使用select语句显示表中的所有记录-

select *from DemoTable;

这将产生以下输出-

+----------+------------+
| ClientId | ClientName |
+----------+------------+
|      101 | Adam       |
|      102 | Chris      |
|      103 | Robert     |
|      104 | Sam        |
|      105 | Mike       |
+----------+------------+
5 rows in set (0.00 sec)
猜你喜欢