« FN_Split() Table Valued Function | Main | Moving Logins Across Multiple SQL Servers »

Renaming SQL Server

Following is a T-SQL script you can use to rename your SQL Server after you have changed the computer name. This script will work if you are connected to the default instance or a named instance. After running the script, you must restart SQL Server for the action to complete.

DECLARE @machinename sysname, @servername sysname, @instancename sysname
SELECT @instancename =
        CASE 
            WHEN charindex('\', @@servername) = 0 THEN '' 
            ELSE SUBSTRING(@@servername, 
                 CHARINDEX('\', @@servername), (len(@@servername)+ 1) - 
                 CHARINDEX('\', @@servername)) 
            END
SET @machinename = convert(nvarchar(100), serverproperty('machinename')) + @instancename;
EXEC sp_dropserver @@servername;
EXEC sp_addserver @machinename, 'local'

Posted on Friday, December 1, 2006 at 11:49AM by Registered CommenterJeff Jones in , | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.
Editor Permission Required
You must have editing permission for this entry in order to post comments.