• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

how to create Windows user using t-sql

hello, using T-SQL, how do i create Windows user  with Administrator rights ?
0
dynamicrevolutions
Asked:
dynamicrevolutions
4 Solutions
 
dduserCommented:
Check out sp_addlogin login in BOL

Regards,

dduser
0
 
dduserCommented:
Also check sp_grantdbaccess in BOL

Regards,

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

Regards,

dduser
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now