Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL MERGE to remote (linked) server table

Is it possible to utilize the SQL MERGE function on a linked server's database table? The end goal is to synchronize the remote table with our local SQL server table. I’ve done some research online and couldn’t find any related information. If it is possible how would you setup the source and target statements?

like image 391
devHead Avatar asked Mar 06 '13 00:03

devHead


People also ask

Can we use MERGE with CTE in SQL?

The MERGE statement syntax specifies USING( table-reference ). Andtable-reference can be a VIEW, and a VIEW can be built over a CTE.

How do I MERGE data from one table to another in SQL Server?

Multiple tables can be merged by columns in SQL using joins. Joins merge two tables based on the specified columns (generally, the primary key of one table and a foreign key of the other). Below is the generic syntax of SQL joins. USING (id);

How can use linked server in SQL Server query?

Right-click on the Linked Server node and choose New Linked Server. In the General tab of the New Linked Server window, choose a name for your linked server, then choose the type of the server you need to connect to using that linked server.


1 Answers

To reiterate the comment by @Mikael Eriksson, yes, you can. The target of a MERGE cannot be remote, but the source of a MERGE can be remote. So, if you can run the MERGE statement from your server in FL, then it is quite possible. For example, you could run something like this on your remove server in FL:

MERGE INTO "local FL table" USING "CT server"."database"."schema"."same table" ON ...
like image 158
Michael Painter Avatar answered Sep 17 '22 15:09

Michael Painter