使用单个MySQL查询将所有值插入表中,并用逗号分隔记录
让我们首先创建一个表-
mysql> create table if not exists DemoTable1343 -> ( -> `_ClientId` int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(40), -> ClientProjectDeadline date -> )ENGINE=MyISAM,AUTO_INCREMENT=1000;
使用插入命令通过单个查询在表中插入一些记录-
mysql> insert into DemoTable1343(ClientName,ClientProjectDeadline) values('Chris','2019-09-24'),('Bob','2015-12-09'), -> ('Mike','2017-01-20'),('Carol','2018-03-31'); Records: 4 Duplicates: 0 Warnings: 0
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1343;
这将产生以下输出-
+-----------+------------+-----------------------+ | _ClientId | ClientName | ClientProjectDeadline | +-----------+------------+-----------------------+ | 1000 | Chris | 2019-09-24 | | 1001 | Bob | 2015-12-09 | | 1002 | Mike | 2017-01-20 | | 1003 | Carol | 2018-03-31 | +-----------+------------+-----------------------+ 4 rows in set (0.00 sec)