how to create Windows user using t-sql

hello, using T-SQL, how do i create Windows user  with Administrator rights ?
LVL 5
dynamicrevolutionsAsked:
Who is Participating?
 
NightmanCTOCommented:
And if you mean 'How do I create a Windows Domain user and make an administrator on the Domain using T-SQL' the answer is you can't.
0
 
dduserCommented:
Check out sp_addlogin login in BOL

Regards,

dduser
0
 
dduserCommented:
Also check sp_grantdbaccess in BOL

Regards,

dduser
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dduserCommented:
Sorry for the above check out sp_grantlogin, this would achieve what you want.

Regards,

dduser
0
 
Gautham JanardhanCommented:


This example below allows the Windows NT user Corporate\BobJ to connect to SQL Server.

EXEC sp_grantlogin 'Corporate\BobJ'


Although a login can connect to SQL Server after sp_grantlogin has been executed, access to user databases is denied until a user account for the login is created in each database that the login must access. Use sp_grantdbaccess to create a user account in each user database.

Only members of the sysadmin or securityadmin fixed server roles can execute sp_grantlogin.

also check

Use
sp_addsrvrolemember [ @loginame = ] 'login'
    , [ @rolename = ] 'role'


0
 
Eugene ZCommented:


IF you meant to add windows login to sql server logins with sql server sa rights...


USE [master]
GO
EXEC master.dbo.sp_grantlogin @loginame = N'yourdomain\userlogin'
EXEC master.dbo.sp_defaultdb @loginame = N'yourdomain\userlogin', @defdb = N'master'
EXEC master.dbo.sp_defaultlanguage @loginame = N'yourdomain\userlogin'
GO
EXEC master..sp_addsrvrolemember @loginame = N'yourdomain\userlogin', @rolename = N'sysadmin'
GO
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.