我必须将数据从一个基于服务的sql server转发到另一个基于服务的sql server
select * from servernameA.db_name.dbo.table_name
where column in (select column from servernameb.db_name.dbo.table_name)
答案 0 :(得分:0)
那么问题是什么?你可以做到。
使用DISTINCT
在您的查询中稍微改善一点性能。
select * from servernameA.db_name.dbo.table_name
where column in (select DISTINCT column from servernameb.db_name.dbo.table_name)
供您参考:
Query across multiple databases on same server
Selecting data from two different servers in SQL Server
<强> ------------ ----------------编辑强>
这个怎么样?我还没试过这个。试一试。
// connectionString is the connection string for the ServerA..DB1
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
// provide commandText as the SQL query having the full name of Server2..DB2
using (var command = new SqlCommand(commandText, conn))
{
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
// read the result
}
}
}
}