Few days ago, there was complex condition when we had one database on two different server. We were migrating database from one server to another server using nightly backup and restore. Based on database server stored procedures has to run different logic. We came up with two different solutions.
1) When database schema is very much changed, we wrote completely new stored procedure and deprecated older version once it was not needed.
2) When logic depended on Server Name we used global variable @@SERVERNAME. It was very convenient while writing migrating script which depended on server name for the same database.
Syntax:
SELECT @@SERVERNAME AS 'Server Name'
ResultSet:
Server Name
——————–
SQLAUTHORITY
Reference : Pinal Dave (http://blog.SQLAuthority.com)




Thanks
That helped me, Very useful
oh, nice post.
thanks…
Thank you for the post
After changing the server name, the @@SERVERNAME still returns the old server name, any idea where @@SERVERNAME is stored so that I can update it to reflect the new server name?
After changing the server name, the @@SERVERNAME still returns the old server name, any idea where @@SERVERNAME is stored so that I can update it to reflect the new server name?
It seems that SERVERPROPERTY(’servername’) returns the new name of the server.
@Goerge
Did you restart your SQL Server Instance after you changed name?
Also is it a default instance or named instance ?
~ IM.
Yes, we restarted the default instance after renaming the server.
I’m not sure why the @@SERVERNAME has the old name, but at least the SERVERPROPERTY(’servername’) returns the new server name.