How to get current instance name from T-SQL

后端 未结 8 1041
天命终不由人
天命终不由人 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:22

    How about this:

    EXECUTE xp_regread @rootkey='HKEY_LOCAL_MACHINE',
                       @key='SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQl',
                       @value_name='MSSQLSERVER'
    

    This will get the instance name as well. null means default instance:

    SELECT SERVERPROPERTY ('InstanceName')
    

    http://technet.microsoft.com/en-us/library/ms174396.aspx

提交回复
热议问题