I'm trying to determine if there's a way to get a server's alias programmatically?
Scenario: Using SQL Configuration Manager, I've created an alias for the server FQDN\InstanceName as "Murphy". All well and good.
Now, let's say I'm connected to Murphy. When I select @@SERVERNAME and SERVERPROPERTY('ServerName'), I get FQDN\InstanceName
exec sp_dropserver " FQDN\InstanceName"
sp_addserver "Murphy", 'local'
But @@SERVERNAME and SERVERPROPERTY('ServerName') both still return FQDN\InstanceName
I need to do stuff like IF <localservername> = "MURPHY" ...
We're about to get a whole bunch of new servers, and I've realized that I want to never again have to go through all the code and replace the hard coded machine / FQDNs with new ones, when all I should have to do is keep the aliases on the new machines.