SQL Server Administration - User/Login Admin

Add User to a Database role

Adding a sql server user, database role, Windows login, or Windows group to a database role for the current database.

Syntax - SQL Server 2005/2008

sp_addrolemember [ @rolename = ] 'role',
    [ @membername = ] 'security_account'
GO    

--returns 0=ok 1=failed

Example(s) - SQL Server 2005/2008

Adding a database user

The following example adds the database user ericm to the PROD database role.

EXEC sp_addrolemember 'PROD', 'ericm'
GO

Example(s) - SQL Server 2005/2008

Adding a Windows login

The following example adds the Windows login SEASVR\eric to the tngmgr database.

USE tngmgr;
GO
CREATE USER ericm FOR LOGIN [SEASVR\ericm] ;
GO
EXEC sp_addrolemember 'PROD', 'ericm'
 Collapse All    Expand All
Custom Search

SQL Server Information and Resources