Update database table from one SQL Server database table to another?

后端 未结 4 1216
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 07:32

I am trying to update database fields from one SQL Server table to another.

Our production SQL Server is [spdbprod.test.com\\spprod], our QA server is

4条回答
  •  逝去的感伤
    2021-02-05 08:21

    1. You need to add a Linked Server under Server Objects
    2. You can name that Linked Server either with "CHOOSEN-NAME" or [ipaddress , port number]

    how to add a linked server using tsql , please check this link : how to find linked server

    for an example purpose suppose i have named the linked server "DESTINATION_SERVER" , database name is "DESTINATION_DB" and table name is "DESTINATION_TBL". then from your source server your query could be like this below:

    UPDATE t1  
    SET t1.updatecolumn = t2.updatecolumn
    FROM [DESTINATION_SERVER].[DESTINATION_DB].[dbo].[DESTINATION_TBL] t1
    INNER JOIN [SOURCE-SERVER].[SOURCE_DB].[dbo].
    [SOURCE_TBL] t2 ON (t1.matcingcolumn = t2.matchingcolumn)
    

提交回复
热议问题