读书人

求一快速更新另一表数据的sql,该如何解

发布时间: 2012-01-07 21:41:55 作者: rapoo

求一快速更新另一表数据的sql
现有A表和B表,A表中有categoryID字段(有多个产品对应同一个categoryID),B表中有oldcategoryID和newcategoryID字段!
原来A表中的categoryID字段是和B表中的oldcategoryID字段是一样的!现想把A表中的categoryID改换为B表中的newcategoryID!该如何去写sql语句呢?

[解决办法]
update A set A.categoryID=B.newcategoryID from A join B on A.categoryid=B.oldCategoryid
[解决办法]
update A set categoryID=B.newcategoryID from B where A.categoryID=B.oldcategoryID
[解决办法]
--try

update A set categoryID=B.newcategoryID
from B
where A.categoryID=B.oldcategoryID

读书人网 >SQL Server

热点推荐