请教大家个问题。如果我要往表A里添加从表B里查询出的数据 这样的SQL语句应该怎么写?谢谢
保证插入字段与被插入字段格式相同
set nocount on
declare @a table
(
id int,
name varchar(10)
)
declare @b table
(
id int,
name varchar(10)
)
insert into @a
select 1,'AAA'
union all
select 2,'BBB'
union all
select 4,'CCC'
insert into @b
select 5,'DDD'
union all
select 6,'EEE'
select * from @a
select * from @b
insert into @a
select * from @b
select * from @a
set nocount off
/*测试结果
id name
----------- ----------
1 AAA
2 BBB
4 CCC
id name
----------- ----------
5 DDD
6 EEE
id name
----------- ----------
1 AAA
2 BBB
4 CCC
5 DDD
6 EEE
*/