sql语句 怎么从一张表中查询数据插入到另一张表中

如题所述

1、
insert into A([id], ids, [name], type, time)
select [id], null, [name], 'dd', getdate() from B where type='dd'
2、
DECLARE @num int,@i int;
SET @i=0;
SET @num=(select 字段 from 表1 where 条件);
WHILE @i<@num
begin
set @i=@i+1;
insert INTO 表2(字段) SELECT 字段 from 表1 where 条件;
end;
3、
insert into b (column1,datecolumn)
select column1,getdate() from a

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-06-09
目标表table2存在;

Insert into Table2 select * from Table1;
目标表table2不存在;
SELECT * into Table2 from Table1;
第2个回答  2017-06-09
学习下,嵌套的select语句吧
相似回答