首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

一条insert语句怎么插入两条数据

2012-02-28 
一条insert语句如何插入两条数据?一条insert语句如何插入两条数据?给个例子[解决办法]INSERT table_1(ID,N

一条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时,也是按这种格式导出的。

热点排行