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

Relevant Pages

  • Re: Parameterized query problem
    ... Did you use SSMS to configure your SQL Server to use mixed ... Did you then create a SQL Login? ... You might consider using stored procedures ... ... This email account is my spam trap so I ...
  • Re: Please Help
    ... here is how to do it without dynamic sql... ... declare @role sysname, @user sysname ... --create new sql login ... exec sp_addlogin @user,@user ...
  • Connectivity to SQL Server 2000 in Different Domain using SQL Login Failing
    ... I'm trying to connect to a remote office's SQL Server 2000 database. ... I've had someone at the local office create a SQL Login as a SysAdmin ... SQL Server is running on the correct port, ...
  • Snapshot Folder Access: Merge Pull Replication w/ SQL Authenticati
    ... I am using merge pull replication with 10 subscribers and 1 publisher all ... They are not in a trusted domain so I am using SQL ... Added the SQL login to the appropriate PAL; ... Created a Windows account on the publisher for each subscriber; ...
  • Re: SQL 2000 Login Problem
    ... Can you catch native SQL Server error? ... Are you using a SQL login and have ... Windows authentication only enabled? ...