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?

Improve company productivity with a Business Account.Sign Up

x
 
NightmanConnect With a Mentor CTOCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
dduserConnect With a Mentor Commented:
Sorry for the above check out sp_grantlogin, this would achieve what you want.

Regards,

dduser
0
 
Gautham JanardhanConnect With a Mentor Commented:


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 ZConnect With a Mentor Commented:


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.