Can I change a linked server connection, but keep the name the same?

183 Views Asked by At

On my SQL Server instance, I have about 30-40 stored procedures.

In those stored procedures, sometimes I call a table from a linked server something like.

Select *
From Picktickets P
Left Join [JMNYC-AMTDB].[AMTPLUS].[dbo].Picktickets_stage pst1 On P.Company_Code = pst1.Company_Code 

where [JMNYC-AMTDB].[AMTPLUS] is a linked server

https://i.imgur.com/PmcqTAK.png

We are moving this server from our local rack, to the cloud.

So all the data will be the same, but the server will now live in a different place with a new IP and credentials and such.

Can I update this linked server, to remap to the location of the new server, while keeping the name of the server the same, so I don't have to edit all my 40 stored procedures?

I can right click on the Linked Server, and I click Script Linked Server As > Drop to and Create to

I also found another stack overflow answer that said I can do something like

EXEC master.dbo.sp_serveroption 
                @server = N'<SERVERNAME>', 
                @optname = N'name', 
                @optvalue = N'<NEWNAME>'

But my main question is, can I keep the name the same, as it is in my stored procedure? Or is the name an integral part of the connection, and not just an alias?

1

There are 1 best solutions below

0
Ben Thul On

The server name is for this purpose just an alias. What you put in the connection string when defining the linked server is what it will actually connect to. So, to answer your question of "can I keep the name the same?" - yes you can.