Get The Domain Name Of Your SQL Server Machine With T-SQL
From Wiki
How do you get the domain name that your SQL Server machine belongs to with T-SQL code?
You can use the undocumented procedure xp_regread; I have tested this on SQL Server 2005 and on SQL Server 2000. Be advised that since this is an undocumented procedure that it might not be available in the future or it might be changed either because of a service pack or a hot fix. Don't use it as production code!
Here is how to do this
- DECLARE @chvDomainName NVARCHAR(100)
- EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
- 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon',
- N'CachePrimaryDomain',@chvDomainName OUTPUT
- SELECT @chvDomainName AS DomainName
Contributed by:--SQLDenis 16:46, 4 June 2008 (GMT)
Part of SQL Server Admin Hacks


