日期:2014-05-19  浏览次数:20435 次

一次插入多行数据
我在查询分析器中用:

Create   Table   employees
(emp_id   int   primary   key,
last_name   varchar(25),
trainner   varchar(25),
sales   int);
建立了一个表。

然后,插入记录:

Insert   Into   employees(emp_id,last_name,trainner,sales)
Values(1, 'Hardy ', 'Bob ',3),
(2, 'Wallace ', 'Greg ',3),
(3, 'Green ', 'Bob ',2),
(4, 'Marsh ', 'Andy ',2),
(5, 'Brown ', 'Greg ',0);

分析查询有语法错误,想一次插入多条记录,应该怎么做?


------解决方案--------------------

Insert Into employees(emp_id,last_name,trainner,sales)
select 1, 'Hardy ', 'Bob ',3 union all
select 2, 'Wallace ', 'Greg ',3 union all
select 3, 'Green ', 'Bob ',2 union all
select 4, 'Marsh ', 'Andy ',2 union all
select 5, 'Brown ', 'Greg ',0
------解决方案--------------------
insert into department select 1, 'Hardy ', 'Bob ',3
union select 2, 'Wallace ', 'Greg ',3
union select 3, 'Green ', 'Bob ',2
union select 4, 'Marsh ', 'Andy ',2
union select 5, 'Brown ', 'Greg ',0