简体   繁体   中英

Stored Procedure Select data from Server A and Insert data to Server B

I would like to ask about how to write the Stored Procedure Select data from Server A and Insert data to Server B?

1. Create a linked server using steps at below link https://www.sqlshack.com/how-to-create-and-configure-a-linked-server-in-sql-server-management-studio/

  1. Create a synonym for the table from the linked server you are going to use if there is only one table otherwise create synonym for that server so you dont have to use the complete name and if the server changes in future you dont have to go and change in every procedure instead you can just change the synonym.

     CREATE SYNONYM MySyn FOR LinkedServerName.DatabaseName.SchemaName; GO
  2. Use the synonym in your query to fetch the data.

     create procedure procedureName as begin insert into destDB.schema.tablename select * from mysyn.sourcetablename end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM