How to get current instance name from T-SQL

后端 未结 8 1019
天命终不由人
天命终不由人 2021-01-30 05:18

How can I get the SQL Server server and instance name of the current connection, using a T-SQL script?

8条回答
  •  走了就别回头了
    2021-01-30 05:35

    Just found the answer, in this SO question (literally, inside the question, not any answer):

    SELECT @@servername
    

    returns servername\instance as far as this is not the default instance

    SELECT @@servicename
    

    returns instance name, even if this is the default (MSSQLSERVER)

提交回复
热议问题