sql-server – 内连接更新?

前端之家收集整理的这篇文章主要介绍了sql-server – 内连接更新?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个数据库
  1. DB1 and DB2

如何做一些像:

  1. update myServer.DB1.dbo.hotels.Name = myServer.DB2.dbo.hotels.Name
  2.  
  3. join myServer.DB2.dbo.hotels on myServer.DB2.dbo.hotels.Code= myServer.DB1.dbo.hotels.Code
  4. where myServer.DB2.dbo.hotels.CountryCoe != myServer.DB1.dbo.hotels.CountryCode

解决方法

  1. UPDATE h1
  2. SET h1.name = h2.name
  3. FROM myServer.DB1.dbo.hotels h1
  4. JOIN myServer.DB2.dbo.hotels h2
  5. ON h2.Code = h1.Code
  6. WHERE h1.CountryCode <> h2.CountryCode

猜你在找的MsSQL相关文章