sp_addsrvrolemember (Transact-SQL)sp_addsrvrolemember (Transact-SQL)

适用对象: yesSQL ServeryesAzure SQL 数据库noAzure SQL 数据仓库no并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

添加登录名以作为固定服务器角色的成员。Adds a login as a member of a fixed server role.

重要

此功能处于维护模式并且可能会在 Microsoft SQL Server 将来的版本中被删除。This feature is in maintenance mode and may 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. 使用ALTER SERVER ROLE相反。Use ALTER SERVER ROLE instead.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

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

参数Arguments

[ @loginame = ] ' 登录 [ @loginame = ] 'login'
将添加到固定服务器角色中的登录名。Is the name of the login being added to the fixed server role. 登录名sysname ,无默认值。login is sysname, with no default. 登录名可以是SQL ServerSQL Server登录名或 Windows 登录名。login can be a SQL ServerSQL Server login or a Windows login. 如果还没有为 Windows 登录名授予 SQL ServerSQL Server 访问权限,则会自动授予该访问权限。If the Windows login has not already been granted access to SQL ServerSQL Server, access is automatically granted.

[ @rolename = ] ' 角色 [ @rolename = ] 'role'
要添加登录名的固定服务器角色的名称。Is the name of the fixed server role to which the login is being added. 角色sysname,默认值为 NULL,并且必须是下列值之一:role is sysname, with a default of NULL, and must be one of the following values:

  • sysadminsysadmin

  • securityadminsecurityadmin

  • serveradminserveradmin

  • setupadminsetupadmin

  • processadminprocessadmin

  • diskadmindiskadmin

  • dbcreatordbcreator

  • bulkadminbulkadmin

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

备注Remarks

在将登录名添加到固定服务器角色时,该登录名将获得与该角色相关的权限。When a login is added to a fixed server role, the login gains the permissions associated with that role.

无法更改 sa 登录名和公共角色成员身份。The role membership of the sa login and public cannot be changed.

使用 sp_addrolemember 将成员添加到固定的数据库角色或用户定义的角色。Use sp_addrolemember to add a member to a fixed database or user-defined role.

不能在用户定义的事务内执行 sp_addsrvrolemember。sp_addsrvrolemember cannot be executed within a user-defined transaction.

权限Permissions

需要具有要添加新成员的角色中的成员身份。Requires membership in the role to which the new member is being added.

示例Examples

下面的示例添加的 Windows 登录名Corporate\HelenSsysadmin固定的服务器角色。The following example adds the Windows login Corporate\HelenS to the sysadmin fixed server role.

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

请参阅See Also

安全存储过程 (Transact-SQL) Security Stored Procedures (Transact-SQL)
sp_addrolemember (Transact-SQL) sp_addrolemember (Transact-SQL)
sp_dropsrvrolemember (TRANSACT-SQL) sp_dropsrvrolemember (Transact-SQL)
系统存储过程 (Transact-SQL) System Stored Procedures (Transact-SQL)
安全函数 (Transact-SQL) Security Functions (Transact-SQL)
CREATE SERVER ROLE (Transact-SQL) CREATE SERVER ROLE (Transact-SQL)
DROP SERVER ROLE (Transact-SQL)DROP SERVER ROLE (Transact-SQL)