Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to create user by query as ...

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2010-03-22 : 01:46:42
hi

I want to create user for particular DB with all permission(Administrator) using query

regards
ASIF

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-22 : 02:30:20
Try it if it helps..

Declare @NewUser Varchar(255)
Set @NewUser ='MyDBNewUser2'

Exec('CREATE LOGIN ' + @NewUser +
' WITH PASSWORD = ''hai'' ')


EXEC master..sp_addsrvrolemember @loginame = @NewUser, @rolename = N'sysadmin'
GO

Regards,
Bohra
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-22 : 02:33:37
Find the template for create user for sysadmin in sql server template explorer from
view -> template explorer

Vaibhav T
Go to Top of Page
   

- Advertisement -