日期:2014-05-19  浏览次数:20462 次

求一快速更新另一表数据的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