34,588
社区成员
发帖
与我相关
我的任务
分享
create table ta(a int)
create table ta2(b int ,c int)
insert into ta
select 1 union all
select 2 union all
select 3 union all
select 4
insert into ta2(b,c)
select 0,null union all
select 0,2 union all
select 0,null union all
select 0,4
--select * from ta
--select * from ta2
update ta2 set c=ta.a from ta
--where 1=1 找个条件关联就ok
--...后面条件没有当然更新所有啦 原本想让你自己加条件的
/*
将表中数据删除后重新添加....
最好ta2表中的数量少于ta 否则改改连接....
*/
declare @tab table(b int,c int)
insert into @tab
select b,a from
(select *,ROW_NUMBER() over(order by(select 1)) as id from ta2) t
inner join (select *,ROW_NUMBER() over(order by(select 1)) as id from ta) tab
on tab.id=t.id
--select * from @tab
delete from ta2 with(tablock)
insert into ta2
select * from @tab
select * from ta2
------------
0 1
0 2
0 3
0 4