Sunday, March 25, 2012

Adding a database user

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,
SteveSteve,
Do you mean a User or a Login or both? There is a difference and a User is
no good without an associated Login. You may want to check out sp_adduser
and sp_addlogin in BooksOnLine.
Andrew J. Kelly
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
>|||Hi,
Also have a look into the system procedures which allocate fixed roles to
users/logins in books online.
sp_addsrvrolemember and sp_addrolemember
Thanks
Hari
MCDBA
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:ORPqt3OREHA.3012@.tk2msftngp13.phx.gbl...
> Steve,
> Do you mean a User or a Login or both? There is a difference and a User
is
> no good without an associated Login. You may want to check out sp_adduser
> and sp_addlogin in BooksOnLine.
> --
> Andrew J. Kelly
> SQL Server MVP
>
> "Steve Caliendo" <scaliendo@.epion.com> wrote in message
> news:e4Rvg8NREHA.1308@.TK2MSFTNGP10.phx.gbl...
I[vbcol=seagreen]
users,[vbcol=seagreen]
>|||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
>

No comments:

Post a Comment