?
Solved

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

Posted on 2004-08-07
1
Medium Priority
?
2,136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
BillAn1 earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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