--> 测试数据: @A
declare@A table(id int,c1 varchar(1),c2 varchar(1),c3 varchar(1))
insertinto@A
select1,'a','b','c'unionall
select2,'d','e','f'unionall
select3,'g','h','i'
--> 测试数据: @B
declare@B table(id int,c1 varchar(1),c2 varchar(1),c3 varchar(1))
insertinto@B
select4,'j','k','l'unionall
select5,'m','n','o'unionall
select6,'p','q','r'unionall
select7,'s','t','u'
--例如更新@A的第二条变成@B的id=6的数据
update@A
setc1=b.c1 ,c2=b.c2,c3=b.c3
from@A a,@B b wherea.id=2 andb.id=6
select* from@A
/*
id c1 c2 c3
----------- ---- ---- ----
1 a b c
2 p q r
3 g h i
*/
网友评论