How to get current instance name from T-SQL

后端 未结 8 1012
天命终不由人
天命终不由人 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 to add some clarification to the registry queries. They only list the instances of the matching bitness (32 or 64) for the current instance.

    The actual registry key for 32-bit SQL instances on a 64-bit OS is:

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server
    

    You can query this on a 64-bit instance to get all 32-bit instances as well. The 32-bit instance seems restricted to the Wow6432Node so cannot read the 64-bit registry tree.

提交回复
热议问题