sql 表与表之间导数据

来源:百度知道 编辑:UC知道 时间:2024/06/05 06:06:52
我有表A , B , 数据列为 uid,username,nickname,password ,uid 数字需要按顺序往下排,两表相同,
现在我要把 B 表的数据导入到A表,并根据A表的最后行 uid ,更新b表的uid 后加入到 a表,请教各位,sql 该怎么写?

declare @uida int,@uidb int
select * into #temp from B
select @uida=max(uid) from A
select @uida=@uida+1
declare cur cursor for select uid from B
open cur
fetch next from cur into @uidb
while @@fetch_status=0
begin
update #temp set uid=@uida where uid=@uidb
select @uida=@uida+1
fetch next from cur into @uidb
end
close cur
deallocate cur
insert into A select * from #temp
drop table #temp

以上,希望对你有所帮助!

insert into A select * from B
把B表中的数据保存到A表中

有点不太懂什么意思

select * into B from A