Get local server's alias in T-SQL

  • Hello,

    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

    I tried

    exec sp_dropserver " FQDN\InstanceName"
    go
    sp_addserver "Murphy", 'local'
    go?

    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.

    Thanks!!

     

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • Hmmm... my OP had appeared to time-out without posting, which is why I reposted the question.

     

    The solution was to restart the SQL Server service.

  • This is a change that requires a restart for the service. Glad you got it working.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply