25

I tried using EXEC sp_who2; to find the server's domain name, but it gives host, users, etc.

I need to know my SQL Server's domain name, so I can install a plugin to the SQL Server Management Studio.

Fandango68
  • 4,461
  • 4
  • 39
  • 74

2 Answers2

53

In T-SQL, you would use this to query the Domain Name of the SQL Server:

SELECT DEFAULT_DOMAIN()[DomainName]
MikeTeeVee
  • 18,543
  • 7
  • 76
  • 70
  • 1
    If the server is running on a non-domain-member system this gives the workgroup name. How can you tell if the return value is really a domain name and not a workgroup name? – Kevin Martin May 07 '22 at 03:37
10

Get your FQDN like so:

DECLARE @Domain varchar(100)

EXEC master..xp_regread
     @rootkey = 'HKEY_LOCAL_MACHINE'
    ,@key = 'SYSTEM\ControlSet001\Services\Tcpip\Parameters\'
    ,@value_name = 'Domain'
    ,@value = @Domain OUTPUT

SELECT @@SERVERNAME AS [@@SERVERNAME]
    ,@Domain AS [@Domain]
Oreo
  • 529
  • 3
  • 16
Mark
  • 687
  • 7
  • 12