sp_addsrvrolemember (Transact-SQL)

Applies to: SQL Server

Adds a login, or security principal, as a member of a fixed server role.

Important

This feature will be removed in a future version of 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.

Transact-SQL syntax conventions

Syntax

sp_addsrvrolemember
    [ @loginame = ] N'loginame'
    [ , [ @rolename = ] N'rolename' ]
[ ; ]

Arguments

[ @loginame = ] N'loginame'

The name of the security principal being added to the fixed server role. @loginame is sysname, with no default. @loginame can be a SQL Server login or a Windows account. If the Windows account isn't already granted access to SQL Server, access is automatically granted.

[ @rolename = ] N'rolename'

The name of the fixed server role to which the security principal is being added. @rolename is sysname, with a default of NULL, and must be one of the following values:

  • sysadmin
  • securityadmin
  • serveradmin
  • setupadmin
  • processadmin
  • diskadmin
  • dbcreator
  • bulkadmin

Return code values

0 (success) or 1 (failure).

Remarks

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

The role membership of the sa user and public can't be changed.

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

sp_addsrvrolemember can't be executed within a user-defined transaction.

Permissions

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

Examples

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

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