日期:2014-05-16  浏览次数:20784 次

一条insert语句如何插入两条数据?
一条insert语句如何插入两条数据?
给个例子

------解决方案--------------------
INSERT table_1(ID,Name) SELECT '1111','john' UNION SELECT '1112','kitty';
------解决方案--------------------
INSERT table_1(ID,Name) values(1,'aa'),(2,'bb')
------解决方案--------------------
INSERT INTO test (name, pwd) VALUES (name1, pwd1),(name2,pwd2),(name3,pwd3),。。。;
------解决方案--------------------
SQL code
 insert into t  values (1),(2);

------解决方案--------------------
INSERT INTO test (name, pwd) VALUES (name1, pwd1),(name2,pwd2);
------解决方案--------------------
没条数据之间用逗号隔开,你可以打开dump一个SQL文件,然后打开看看
------解决方案--------------------
insert into table1 (col1,col2) values (v1,v2),(v3,v4);

这是MYSQL中特有的语法。

MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
------解决方案--------------------
mysql> create table testdate(id int primary key, startdate date, days int);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into testdate values(1, '2010-04-11', 15);
Query OK, 1 row affected (0.03 sec)

mysql> select * from testdate;
+----+------------+------+
| id | startdate | days |
+----+------------+------+
| 1 | 2010-04-11 | 15 | 
+----+------------+------+
1 row in set (0.00 sec)
mysql> insert into testdate values(2, '2010-05-11', 10), (3, '2010-06-29', 1);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from testdate;
+----+------------+------+
| id | startdate | days |
+----+------------+------+
| 1 | 2010-04-11 | 15 | 
| 2 | 2010-05-11 | 10 | 
| 3 | 2010-06-29 | 1 | 
+----+------------+------+
3 rows in set (0.00 sec)



------解决方案--------------------
create table haha
(
hid int not null,
haname varchar(50) not null
);

insert into haha(hid,haname) values (1,'haha'),(2,'hehe')

select * from haha

恩,可以的,本人亲手试过
------解决方案--------------------
create table haha
(
hid int not null,
haname varchar(50) not null
);

insert into haha(hid,haname) values (1,'haha'),(2,'hehe')

select * from haha
有效,那个sql-yag 的客户端导出sql时,也是按这种格式导出的。