sqlserver 如何实现把一个表里的数据 以追加列的形式添加到另一个表中
是这样的,我想把 A表的数据以添加列的形式添加到B表(A,B量表的行是相等的)
比如A表有2列B有5列要把A的两列加到B中B变成7列,其中A.ID=B.ID
求高手解答
[解决办法]
select * from a
union all
select * from b
if object_id('A') IS NOT NULL
DROP TABLE A
go
create table A
(
id int,
Code varchar(10)
)
go
if object_id('B') IS NOT NULL
DROP TABLE B
go
create table B
(
id int,
Code varchar(10)
)
go
insert into a
select 1,'A001' UNION ALL
select 2,'A002' UNION ALL
select 3,'A003'
GO
INSERT INTO B
select 1,'B001' UNION ALL
select 2,'B002' UNION ALL
select 3,'B003'
GO
--select * from a
--union all
--select * from b
insert into B
select A.* FROM A,B WHERE A.ID = B.ID
GO
select * from B