SQL 使用另一个数据库中的数据更新字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4921597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update field with data from another database
提问by MikeRTeixeira
Need to update a field with data from another field in a different database
需要使用不同数据库中另一个字段的数据更新一个字段
I Have two SQL commercial Databases from the same company, the first Database has one field that is null in the other
我有来自同一家公司的两个 SQL 商业数据库,第一个数据库的一个字段在另一个中为空
I need to update the Field/Database that is null with the data of the first one.
我需要用第一个的数据更新为空的字段/数据库。
回答by Mikael Eriksson
MS SQL Server
微软 SQL 服务器
Update table1 in current database from table1 in database called "DataBaseName"
从名为“DataBaseName”的数据库中的 table1 更新当前数据库中的 table1
update table1
set col2 = T2.col2
from DataBaseName.dbo.table1 as T2
where table1.ID = T2.ID and
table1.col2 is null