Find Domain Name Using T-SQL | SansSQL

Monday, November 17, 2008

Find Domain Name Using T-SQL

DECLARE @Domain varchar(100), @key varchar(100)

SET @key = 'SYSTEM\ControlSet001\Services\Tcpip\Parameters\'
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key=@key,@value_name='Domain',@value=@Domain OUTPUT
SELECT 'Server Name: '+@@servername + ' Domain Name:'+convert(varchar(100),@Domain)

Alternative ways,
1. SELECT DEFAULT_DOMAIN()
2. EXEC Master.dbo.xp_LoginConfig 'Default Domain'

5 comments:

Anonymous said...

Worked for me. Thank you.
(Nice site)

Paul Goldy said...

Thanks Sandesh. Very helpful SQL.

Paul Goldy said...

Thanks Sandesh. Very helpful SQL.

ArdentAj said...

When I tried this query it is throwing up Access Denied error.I think DBA haven't granted access for registry variables.

So is there any another way I can get Full computer name

Sandesh Segu said...

You can try either of the below queries

SELECT DEFAULT_DOMAIN()

EXEC Master.dbo.xp_LoginConfig 'Default Domain'

Post a Comment