Re: Adding a database user

From: Dan Guzman (danguzman_at_nospam-earthlink.net)
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
user

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" <scaliendo@epion.com> wrote in message
news:e4Rvg8NREHA.1308@TK2MSFTNGP10.phx.gbl...
> 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: 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 ...
    (microsoft.public.sqlserver.security)
  • 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, ...
    (microsoft.public.sqlserver.security)
  • Re: SQL 2000 Login Problem
    ... Can you catch native SQL Server error? ... Are you using a SQL login and have ... Windows authentication only enabled? ...
    (microsoft.public.sqlserver.setup)
  • Re: sa login
    ... automatically makes you a member of the SYSADMIN role in SQL Server 2000. ... > instance is set to Windows autentication only. ... > connect using the SQL login - it works. ...
    (microsoft.public.sqlserver.security)
  • Re: Connection to a MS SQL Server Table (newbie)
    ... > home machines with IIS and MS SQL Server. ... you would create a sql login with limited permissions in your ... > It is basically a departmental personnel database tailored to our ... Please reply to the newsgroup. ...
    (microsoft.public.inetserver.asp.db)