SQL Server Migration – Server Name in Stored Procedures References Old Server

migrationsql server

I will migrate an SQL server from 2000 to 2008 R2. It contains two instances. I have many stored procedures that are referencing the instance names like:

select ... from [old_server\instance1].db1.dbo.table1

What is the best way to deal with these stored procedures?

  1. Modify all stored procedures and change these occurrences
    from [old_server\instance1].db1.dbo.table1 to [new_server\instance1].db1.dbo.table1
  2. Do not change the stored procedures, but create a reference from the old server to the new one using sp_setnetname
  3. Rename the new server after the migration to keep the old name

Best Answer

If I have to make the choice, I'd rather alter the stored procedure to replace the hard-coded old server name with the new server name because it is pretty straight-forward doing this manually. Just script out all the stored procedures using SSMS and then find and replace the old server name and re-run the script.

Of course, you can use PowerShell to automatically script out each SP and alter them at the same time.