SQL Technology

Rename SQL @@Servername

This script will show you what the old server name was and what the current server name is. Even though you rename the machine name through windows system advanced properties, theSQL server name stays what it was on original install date.

	SELECT ServerProperty('machinename') as [machinename]
	,ServerProperty('ServerName') as [ServerName]
	,@@ServerName as [@@ServerName];

I recently needed to inject the name of the SQL server into a script that exported blob data to a file system. I used @@servername but to my surprise it returned the name of the server that the SQL server used to be. I cloned this a production server to do some testing and renamed the server.

USe Master
		EXEC sp_dropserver 'NETSQL3';
	EXEC sp_addserver 'NET3', 'local';

This SQL command will rename the server variable value for @@servername.

Leave a Reply