Solved

SQL Server - How to add user to database from transact sql

Posted on 2004-08-07
1
2,126 Views
Last Modified: 2011-10-03
Hello All,

Is it possible to add a user to a SQL Server database using Transact SQL, instead of Enterprise Manager?  If so, can you give me an example?

Thanks!
0
Comment
Question by:quiTech
1 Comment
 
LVL 17

Accepted Solution

by:
BillAn1 earned 500 total points
ID: 11744692
The following will add a new user, and add them to the db_owner role for the current database

for further parameters look at the help for the 3 stored procs

sp_addlogin @loginame = 'newuser', @passwd = 'newpass'
sp_grantdbaccess 'newuser'
sp_addrolemember 'db_owner', 'newuser'
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now