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
Solved

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best RAID for a BDD Oracle 4 78
Index Details in SQL Server 2012 4 57
Server configuration for MS Access - SQL Server app 8 77
Multiple MSSQL instances on same server 4 47
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

809 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