美文网首页
SQL 用update多个字段

SQL 用update多个字段

作者: 令狐达耶 | 来源:发表于2019-02-21 17:11 被阅读0次

--> 测试数据: @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

*/

相关文章

网友评论

      本文标题:SQL 用update多个字段

      本文链接:https://www.haomeiwen.com/subject/herdyqtx.html