Solved

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

Posted on 2004-08-07
1
2,127 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spx for moving values to new table 5 70
MSSQL: Query to convert field in a row into several rows 29 95
microsoft access question 8 50
Steps to produce a data strategy 5 40
Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
This article describes some very basic things about SQL Server filegroups.
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…

911 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