数据库中 把A表中的a字段和b字段数据 复制到B表中的aa字段和bb字段?
3个回答
展开全部
如果你存在ab表,那么需要用insert into,如果不存在b表,那么用select * into
DB Code(sqlserver2005)
if not exists (select * from sysobjects where name='tab1')
begin
create table tab1
(
id int primary key identity(1,1),
column1 varchar(20),
column2 varchar(20)
)
end
Go
if not exists (select * from tab1)
begin
declare @number int,@strNumber varchar(10)
set @number=1
while @number<=10
begin
set @strNumber=ltrim(str(@number))
insert into tab1 values ('column1-Data'+@strNumber,'column2-Data'+@strNumber)
set @number=@number+1
end
end
Go
select * from tab1
Go
if not exists(select * from sysobjects where name='tab2')
begin
select column1,column2 into tab2 from tab1
end
else
begin
insert into tab2 (column1,column2) select column1,column2 from tab1
end
DB Code(sqlserver2005)
if not exists (select * from sysobjects where name='tab1')
begin
create table tab1
(
id int primary key identity(1,1),
column1 varchar(20),
column2 varchar(20)
)
end
Go
if not exists (select * from tab1)
begin
declare @number int,@strNumber varchar(10)
set @number=1
while @number<=10
begin
set @strNumber=ltrim(str(@number))
insert into tab1 values ('column1-Data'+@strNumber,'column2-Data'+@strNumber)
set @number=@number+1
end
end
Go
select * from tab1
Go
if not exists(select * from sysobjects where name='tab2')
begin
select column1,column2 into tab2 from tab1
end
else
begin
insert into tab2 (column1,column2) select column1,column2 from tab1
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询