Re: Adding a database user

From: Dan Guzman (
Date: 05/29/04

Date: Sat, 29 May 2004 09:31:49 -0500

To add to the other responses:

Use sp_addlogin to add a new SQL login.

Use sp_grantlogin to grant an existing Windows account access to SQL Server

Use sp_grantdbaccess to add a SQL login or Windows account as a database

For example:

EXEC sp_addlogin 'MySqlLogin', 'MyPassword'
EXEC sp_grantlogin 'MyDomain\MyAccount'
USE MyDatabase
EXEC sp_grantdbaccess 'MySqlLogin'
EXEC sp_grantdbaccess 'MyDomain\MyAccount'

See the Books Online for details.

Hope this helps.
Dan Guzman
SQL Server MVP
"Steve Caliendo" <> wrote in message
> Hi,
> Could someone please tell me how to add a database user using a query?  I
> know how to set the appropriate permissions for tables of existing users,
> but I can't figure out how to add a new user.
> Thank you,
> Steve