sp_addsrvrolemember (Transact-SQL)
Collapse the table of content
Expand the table of content

sp_addsrvrolemember (Transact-SQL)

Adds a login as a member of a fixed server role.

Important note Important

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use ALTER SERVER ROLE instead.

Topic link icon Transact-SQL Syntax Conventions

sp_addsrvrolemember [ @loginame= ] 'login' 
    , [ @rolename = ] 'role'

[ @loginame = ] 'login'

Is the name of the login being added to the fixed server role. login is sysname, with no default. login can be a SQL Server login or a Windows login. If the Windows login has not already been granted access to SQL Server, access is automatically granted.

[ @rolename = ] 'role'

Is the name of the fixed server role to which the login is being added. role is sysname, with a default of NULL, and must be one of the following values:

  • sysadmin

  • securityadmin

  • serveradmin

  • setupadmin

  • processadmin

  • diskadmin

  • dbcreator

  • bulkadmin

0 (success) or 1 (failure)

When a login is added to a fixed server role, the login gains the permissions associated with that role.

The role membership of the sa login and public cannot be changed.

Use sp_addrolemember to add a member to a fixed database or user-defined role.

sp_addsrvrolemember cannot be executed within a user-defined transaction.

Requires membership in the role to which the new member is being added.

The following example adds the Windows login Corporate\HelenS to the sysadmin fixed server role.

EXEC sp_addsrvrolemember 'Corporate\HelenS', 'sysadmin';

Community Additions

© 2015 Microsoft