GRANT 数据库主体权限 (Transact-SQL)GRANT Database Principal Permissions (Transact-SQL)

适用对象:是SQL Server 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 是并行数据仓库 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

授予对 SQL ServerSQL Server 中数据库用户、数据库角色或应用程序角色的权限。Grants permissions on a database user, database role, or application role in SQL ServerSQL Server.

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

语法Syntax

GRANT permission [ ,...n ]    
    ON   
    {  [ USER :: database_user ]  
     | [ ROLE :: database_role ]  
     | [ APPLICATION ROLE :: application_role ]  
    }  
    TO <database_principal> [ ,...n ]  
       [ WITH GRANT OPTION ]  
       [ AS <database_principal> ]  
  
<database_principal> ::=  
    Database_user   
  | Database_role   
  | Application_role   
  | Database_user_mapped_to_Windows_User   
  | Database_user_mapped_to_Windows_Group   
  | Database_user_mapped_to_certificate   
  | Database_user_mapped_to_asymmetric_key   
  | Database_user_with_no_login   

参数Arguments

permission Permission
指定可对数据库主体授予的权限。Specifies a permission that can be granted on the database principal. 有关权限的列表,请参阅本主题后面的“备注”部分。For a list of the permissions, see the Remarks section later in this topic.

USER ::database_user USER ::database_user
指定要对其授予权限的用户的类和名称。Specifies the class and name of the user on which the permission is being granted. 需要作用域限定符 ::。The scope qualifier (::) is required.

ROLE ::database_role ROLE ::database_role
指定要对其授予权限的角色的类和名称。Specifies the class and name of the role on which the permission is being granted. 需要作用域限定符 ::。The scope qualifier (::) is required.

APPLICATION ROLE ::application_role APPLICATION ROLE ::application_role

指定要对其授予权限的应用程序角色的类和名称。Specifies the class and name of the application role on which the permission is being granted. 需要作用域限定符 ::。The scope qualifier (::) is required.

WITH GRANT OPTIONWITH GRANT OPTION
指示该主体还可以向其他主体授予所指定的权限。Indicates that the principal will also be given the ability to grant the specified permission to other principals.

AS <database_principal>AS <database_principal>
指定一个主体,执行该查询的主体从该主体获得授予该权限的权利。Specifies a principal from which the principal executing this query derives its right to grant the permission.

Database_user Database_user
指定数据库用户。Specifies a database user.

Database_role DATABASE_ROLE
指定数据库角色。Specifies a database role.

Application_role applicationRole
适用于SQL Server 2008SQL Server 2008 及更高版本、SQL 数据库SQL Database Applies to: and later, .

指定应用程序角色。Specifies an application role.

Database_user_mapped_to_Windows_User Database_user_mapped_to_Windows_User
指定映射到 Windows 用户的数据库用户。Specifies a database user mapped to a Windows user.

Database_user_mapped_to_Windows_Group Database_user_mapped_to_Windows_Group

指定映射到 Windows 组的数据库用户。Specifies a database user mapped to a Windows group.

Database_user_mapped_to_certificate Database_user_mapped_to_certificate

指定映射到证书的数据库用户。Specifies a database user mapped to a certificate.

Database_user_mapped_to_asymmetric_key Database_user_mapped_to_asymmetric_key

指定映射到非对称密钥的数据库用户。Specifies a database user mapped to an asymmetric key.

Database_user_with_no_login Database_user_with_no_login
指定无相应服务器级主体的数据库用户。Specifies a database user with no corresponding server-level principal.

备注Remarks

可以在 sys.database_principals 目录视图中查看有关数据库主体的信息。Information about database principals is visible in the sys.database_principals catalog view. 可以在 sys.database_permissions 目录视图中查看有关数据库级权限的信息。Information about database-level permissions is visible in the sys.database_permissions catalog view.

数据库用户权限Database User Permissions

数据库用户是一个数据库级的安全对象,包含于权限层次结构中作为其父级的数据库中。A database user is a database-level securable contained by the database that is its parent in the permissions hierarchy. 下表列出了可授予的对数据库用户最为具体的限定权限,以及隐含这些权限的更为通用的权限。The most specific and limited permissions that can be granted on a database user are listed in the following table, together with the more general permissions that include them by implication.

数据库用户权限Database user permission 数据库用户权限隐含的权限Implied by database user permission 数据库权限隐含的权限Implied by database permission
CONTROLCONTROL CONTROLCONTROL CONTROLCONTROL
IMPERSONATEIMPERSONATE CONTROLCONTROL CONTROLCONTROL
ALTERALTER CONTROLCONTROL ALTER ANY USERALTER ANY USER
VIEW DEFINITIONVIEW DEFINITION CONTROLCONTROL VIEW DEFINITIONVIEW DEFINITION

数据库角色权限Database Role Permissions

数据库角色是一个数据库级的安全对象,包含于权限层次结构中作为其父级的数据库中。A database role is a database-level securable contained by the database that is its parent in the permissions hierarchy. 下表列出了可授予的对数据库角色最为具体的限定权限,以及隐含这些权限的更为通用的权限。The most specific and limited permissions that can be granted on a database role are listed in the following table, together with the more general permissions that include them by implication.

数据库角色权限Database role permission 数据库角色权限隐含的权限Implied by database role permission 数据库权限隐含的权限Implied by database permission
CONTROLCONTROL CONTROLCONTROL CONTROLCONTROL
TAKE OWNERSHIPTAKE OWNERSHIP CONTROLCONTROL CONTROLCONTROL
ALTERALTER CONTROLCONTROL ALTER ANY ROLEALTER ANY ROLE
VIEW DEFINITIONVIEW DEFINITION CONTROLCONTROL VIEW DEFINITIONVIEW DEFINITION

应用程序角色权限Application Role Permissions

应用程序角色是一个数据库级的安全对象,包含于权限层次结构中作为其父级的数据库中。An application role is a database-level securable contained by the database that is its parent in the permissions hierarchy. 下面列出了可授予的对应用程序角色最为具体的限定权限,以及隐含这些权限的更为通用的权限。The most specific and limited permissions that can be granted on an application role are listed in the following, together with the more general permissions that include them by implication.

应用程序角色权限Application role permission 应用程序角色权限隐含的权限Implied by application role permission 数据库权限隐含的权限Implied by database permission
CONTROLCONTROL CONTROLCONTROL CONTROLCONTROL
ALTERALTER CONTROLCONTROL ALTER ANY APPLICATION ROLEALTER ANY APPLICATION ROLE
VIEW DEFINITIONVIEW DEFINITION CONTROLCONTROL VIEW DEFINITIONVIEW DEFINITION

权限Permissions

授权者(或用 AS 选项指定的主体)必须具有带 GRANT OPTION 的相同权限,或具有隐含所授予权限的更高权限。The grantor (or the principal specified with the AS option) must have either the permission itself with GRANT OPTION, or a higher permission that implies the permission being granted.

若要使用 AS 选项,还必须满足以下附加要求:If you are using the AS option, the following additional requirements apply.

AS granting_principal AS granting_principal 所需的其他权限Additional permission required
数据库用户Database user 对用户的 IMPERSONATE 权限、db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。IMPERSONATE permission on the user, membership in the db_securityadmin fixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
映射到 Windows 用户的数据库用户Database user mapped to a Windows User 对用户的 IMPERSONATE 权限、db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。IMPERSONATE permission on the user, membership in the db_securityadmin fixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
映射到 Windows 组的数据库用户Database user mapped to a Windows Group Windows 组的成员身份、db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。Membership in the Windows group, membership in the db_securityadmin fixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
映射到证书的数据库用户Database user mapped to a certificate db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。Membership in the db_securityadmin fixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
映射到非对称密钥的数据库用户Database user mapped to an asymmetric key db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。Membership in the db_securityadminfixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
未映射到任何服务器主体的数据库用户Database user not mapped to any server principal 对用户的 IMPERSONATE 权限、db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。IMPERSONATE permission on the user, membership in the db_securityadmin fixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
数据库角色Database role 对角色的 ALTER 权限、db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。ALTER permission on the role, membership in the db_securityadminfixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.
应用程序角色Application role 对角色的 ALTER 权限、db_securityadmin 固定数据库角色的成员身份、db_owner 固定数据库角色的成员身份或 sysadmin 固定服务器角色的成员身份。ALTER permission on the role, membership in the db_securityadmin fixed database role, membership in the db_owner fixed database role, or membership in the sysadmin fixed server role.

对某安全对象具有 CONTROL 权限的主体可以授予对该安全对象的权限。Principals that have CONTROL permission on a securable can grant permission on that securable.

将某一数据库的 CONTROL 权限授予用户(例如,db_owner 固定数据库角色的成员)后,该用户就可授予对该数据库中任何一个安全对象的任意权限。Grantees of CONTROL permission on a database, such as members of the db_owner fixed database role, can grant any permission on any securable in the database.

示例Examples

A.A. 将对某个用户的 CONTROL 权限授予另一个用户Granting CONTROL permission on a user to another user

以下示例将对 CONTROL 用户 AdventureWorks2012Wanida 权限授予用户 RolandXThe following example grants CONTROL permission on AdventureWorks2012 user Wanida to user RolandX.

GRANT CONTROL ON USER::Wanida TO RolandX;  
GO  

B.B. 使用 GRANT OPTION 将对角色的 VIEW DEFINITION 权限授予用户Granting VIEW DEFINITION permission on a role to a user with GRANT OPTION

以下示例使用 VIEW DEFINITION,将对 AdventureWorks2012 角色 SammamishParkingGRANT OPTION 权限授予数据库用户 JinghaoLiuThe following example grants VIEW DEFINITION permission on AdventureWorks2012 role SammamishParking together with GRANT OPTION to database user JinghaoLiu.

GRANT VIEW DEFINITION ON ROLE::SammamishParking   
    TO JinghaoLiu WITH GRANT OPTION;  
GO  

C.C. 将对用户的 IMPERSONATE 权限授予应用程序角色Granting IMPERSONATE permission on a user to an application role

以下示例将对用户 IMPERSONATEHamithaL 权限授予 AdventureWorks2012 应用程序角色 AccountsPayable17The following example grants IMPERSONATE permission on user HamithaL to AdventureWorks2012 application role AccountsPayable17.

适用于SQL Server 2008SQL Server 2008 及更高版本、SQL 数据库SQL Database Applies to: and later, .

GRANT IMPERSONATE ON USER::HamithaL TO AccountsPayable17;  
GO    

另请参阅See Also

DENY 数据库主体权限 (Transact-SQL) DENY Database Principal Permissions (Transact-SQL)
REVOKE 数据库主体权限 (Transact-SQL) REVOKE Database Principal Permissions (Transact-SQL)
sys.database_principals (Transact-SQL) sys.database_principals (Transact-SQL)
sys.database_permissions (Transact-SQL) sys.database_permissions (Transact-SQL)
CREATE USER (Transact-SQL) CREATE USER (Transact-SQL)
CREATE APPLICATION ROLE (Transact-SQL) CREATE APPLICATION ROLE (Transact-SQL)
CREATE ROLE (Transact-SQL) CREATE ROLE (Transact-SQL)
GRANT (Transact-SQL) GRANT (Transact-SQL)
权限(数据库引擎) Permissions (Database Engine)
主体(数据库引擎) Principals (Database Engine)