您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_helprotect

语法


sp_helprotect [<name>[, <username>[,'grant'|'deny' 
	[,"none" | "granted" | "enabled" | <role_name>[, <permission_name>]]]]]

参数

<name>

是当前数据库中表、视图、存储过程、SQLJ 存储过程、SQLJ 函数、用户定义函数等的名称或用户、角色或组的名称。如果没有提供名称,则 sp_helprotect 报告数据库中的所有权限。

<username>

是当前数据库中用户、组或角色的名称。

grant

将使用 grant 选项为 <name> 授予的特权显示给<username>。如果 <username> 为空,sp_helprotect 将列出使用 grant 选项为 <name> 授予的所有特权。

deny

显示表、表的所有者、全部表、全部所有者的已拒绝特权,或指定权限名称的状态(是否已拒绝)。

none

在确定授予的权限时忽略授予用户的角色。

granted

在确定授予的权限时包括授予该用户的所有角色的有关信息。

enabled

在确定授予的权限时包括由该用户激活的所有角色的有关信息。

<role_name>

列出通过 <role_name> 授予的特权。

<permission_name>

允许 sp_helprotect 提供有关给定数据库中授予的任何特定权限的信息(授予者名称、被授予者名称、表/列名称和可授权性)。

此参数的值可以是 sysprotects.action 列中的任意值。

示例

示例 1

此 grant 和 revoke 语句系列,执行 sp_helprotect titles 将导致显示以下内容:


grant select on titles to judy 
grant update on titles to judy 
revoke update on titles(price) from judy
grant select on publishers to judy
with grant option
go
sp_helprotect titles

grantor grantee type   action   object   column      predicate  grantable
------- ------  -----  ------   ------   ------      ---------  ---------
dbo     judy    Grant  Select   titles   All         0          FALSE 
dbo     judy    Grant  Update   titles   advance     0          FALSE 
dbo     judy    Grant  Update   titles   notes       0          FALSE 
dbo     judy    Grant  Update   titles   pub_id      0          FALSE 
dbo     judy    Grant  Update   titles   pubdate     0          FALSE 
dbo     judy    Grant  Update   titles   title       0          FALSE 
dbo     judy    Grant  Update   titles   title_id    0          FALSE 
dbo     judy    Grant  Update   titles   total_sales 0          FALSE 
dbo     judy    Grant  Update   titles   type        0          FALSE
dbo     judy    Grant  Select   titles   all         0          TRUE

示例 2

发出以下 grant 语句将导致 sp_helprotect 显示以下内容:


grant select, update on titles(price, advance)
	to mary
	with grant option
go
sp_helprotect titles

grantor   grantee   type    action   object   column   predicate grantable
-------   -------   ------  -------  ------   ------   ---------  --------
dbo       mary      Grant   Select   titles   advance  0          TRUE 
dbo       mary      Grant   Select   titles   price    0          TRUE 
dbo       mary      Grant   Update   titles   advance  0          TRUE 
dbo       mary      Grant   Update   titles   price    0          TRUE 

示例 3

显示“judy”在数据库中具有的所有权限:


sp_helprotect judy

示例 4

显示“csmith”对 sysusers 表具有的任何权限,以及“csmith”是否具有允许“csmith”向其他用户授予权限的 with grant option:


sp_helprotect sysusers, csmith, "grant"

grantor  grantee  type    action     object    column  predicate grantable
-------- -------  ------  ---------  --------  ------  --------- --------
dbo      doctor    Grant  Delete     sysusers  All     0         FALSE
dbo      doctor    Grant  Insert     sysusers  All     0         FALSE
dbo      doctor    Grant  References sysusers  All     0         FALSE

示例 5

显示 doctor 角色在数据库中具有的权限的有关信息:


sp_helprotect doctor

grantor  grantee  type   action     object   column   predicate  grantable
-------  ------  -----  ---------  --------  ------   -------   ----------
dbo      doctor  Grant  Delete     sysusers  All      0         FALSE 
dbo      doctor  Grant  Insert     sysusers  All      0         FALSE 
dbo      doctor  Grant  References sysusers  All      0         FALSE 

示例 6

显示授予“csmith”的所有角色的有关信息:


sp_helprotect csmith, null, null, "granted"

grantor grantee   type   action     object    column  predicate  grantable
------- --------  ------ ---------- --------  ------- ---------- ---------
dbo     csmith    Grant  Update     sysusers  All     0          FALSE
dbo     doctor    Grant  Delete     sysusers  All     0          FALSE
dbo     doctor    Grant  Insert     sysusers  All     0          FALSE
dbo     doctor    Grant  References sysusers  All     0          FALSE

(1 row affected)
(return status = 0)

示例 7

显示授予“rpillai”的所有活动角色的有关信息:


sp_helprotect rpillai, null, null, "enabled"

grantor grantee   type   action object         column  predicate grantable
------- --------  ------ ------ -------------  ------- --------- -------
dbo     public    Grant  Select sysattributes  All     0          FALSE

(1 row affected)
(return status = 0)

示例 8

建议 SQLJ 函数访问是公共的:


sp_helprotect function_sqlj

Implicit grant to public for SQLJ functions.

示例 9

使用 sysprotects.action 中的“Decrypt”操作:


sp_helprotect @permission_name = "Decrypt"

grantor  grantee  type   action   object     column   predicate  grantable
-------  -------- -----  -------  -------    ------   ---------  ---------
sa1      hr_login Grant  Decrypt  employee   ssn      0          TRUE
sa1      hr_role  Grant  Decrypt  employee   ssn      0          FALSE

示例 10

在输出中显示谓词特权的名称:


grant select, update, on tab1 where col1 = 8 as pred1 to robert
grant select, delete on tab1 where col1 = 9 to robert, joffrey
grant select, delete, update on tab1 where col2 = 10 as pred2 to role1,
group1 

sp_helprotect tab1

<h2>grantor  grantee type  action object column predicate          grantable</h2>
 dbo     joffrey Grant Delete tab1   All    tab1_fdoIidqcSKLm  FALSE
 dbo     joffrey Grant Select tab1   All    tab1_fdoIidqcSKLm  FALSE
 dbo     group1  Grant Delete tab1   All    pred2              FALSE
 dbo     group1  Grant Select tab1   All    pred2              FALSE
 dbo     group1  Grant Update tab1   All    pred2              FALSE
 dbo     role1   Grant Delete tab1   All    pred2              FALSE
 dbo     role1   Grant Select tab1   All    pred2              FALSE
 dbo     role1   Grant Update tab1   All    pred2              FALSE
 dbo     robert  Grant Delete tab1   All    tab1_fdoIidqcSKLm  FALSE
 dbo     robert  Grant Select tab1   All    pred1              FALSE
 dbo     robert  Grant Select tab1   All    tab1_fdoIidqcSKLm  FALSE
 dbo     robert  Grant Update tab1   All    pred1              FALSE

示例 11

显示表 t1 的所有权限,包括拒绝的权限:


sp_helprotect t1

<h2>grantor  grantee      type   action              object      column  predicate  grantable</h2>
 dbo     All owners   Deny   Delete              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Delete Statistics   All tables   All     NULL       FALSE
 dbo     All owners   Deny   Insert              All tables   All     NULL       FALSE
 dbo     All owners   Deny   References          All tables   All     NULL       FALSE
 dbo     All owners   Deny   Select              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Transfer Table      All tables   All     NULL       FALSE
 dbo     All owners   Deny   Truncate Table      All tables   All     NULL       FALSE
 dbo     All owners   Deny   Update              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Update Statistics   All tables   All     NULL       FALSE
 dbo     user1        Grant  Select              t1           All     NULL       FALSE
 dbo     user1        Grant  Truncate Table      t1           All     NULL       TRUE

示例 12

使用 allow 以允许一些拒绝的权限,并显示剩下的拒绝权限:


allow update, insert, references on all tables to all owners

sp_helprotect "deny"

<h2>grantor  grantee      type   action              object      column  predicate  grantable</h2>
 dbo     All owners   Deny   Delete              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Delete Statistics   All tables   All     NULL       FALSE
 dbo     All owners   Deny   Select              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Transfer Table      All tables   All     NULL       FALSE
 dbo     All owners   Deny   Truncate Table      All tables   All     NULL       FALSE
 dbo     All owners   Deny   Update Statistics   All tables   All     NULL       FALSE
 

示例 13

当 dbo 是 t1 的所有者时,显示对指定表和用户的权限:


sp_helprotect, dbo

<h2>grantor  grantee      type   action              object      column  predicate  grantable</h2>
 dbo     All owners   Deny   Delete              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Delete Statistics   All tables   All     NULL       FALSE
 dbo     All owners   Deny   Select              All tables   All     NULL       FALSE
 dbo     All owners   Deny   Transfer Table      All tables   All     NULL       FALSE
 dbo     All owners   Deny   Truncate Table      All tables   All     NULL       FALSE
 dbo     All owners   Deny   Update Statistics   All tables   All     NULL       FALSE
 

示例 15

显示特定用户的拒绝权限:


sp_helprotect user1, 'deny'

<h2>grantor  grantee      type   action              object      column  predicate  grantable</h2>
 dbo     All Owners   Deny   Delete              All Tables    All    NULL      FALSE
 dbo     All Owners   Deny   Delete Statistics   All Tables    All    NULL      FALSE
 dbo     All Owners   Deny   Select              All Tables    All    NULL      FALSE
 dbo     All Owners   Deny   Transfer Table      All Tables    All    NULL      FALSE
 dbo     All Owners   Deny   Truncate Table      All Tables    All    NULL      FALSE
 dbo     All Owners   Deny   Update Statistics   All Tables    All    NULL      FALSE

示例 16

显示特定权限的状态:


sp_helprotect 'deny', @permission_name= 'update'

<h2>grantor  grantee      type   action              object      column  predicate  grantable</h2>
 dbo     All Owners   Deny   Update              All Tables   All     NULL      FALSE

用法

  • sp_helprotect 报告对于某一数据库对象的权限。如果提供了 <username> 参数,则只报告此用户对该数据库对象的权限。如果 <name> 不是一个对象,则 sp_helprotect 将检查它是否为用户、组、角色或权限名称。如果它是用户、组或角色,则 sp_helprotect 列出该用户、组或角色的权限。

  • sp_helprotect 只查找当前数据库中的对象和用户。

  • 如果没有指定诸如 granted、enabled、none 或 <role_name> 之类的可选值,SAP ASE 服务器将会返回由当前指定用户激活的所有角色的有关信息。

  • 如果指定用户不是当前用户,则 SAP ASE 服务器会返回授予该指定用户的所有角色的有关信息。

  • 显示的信息始终包括授予该指定用户所在组的权限。

  • 授予权限时,系统管理员被视作对象所有者。如果系统管理员授予对另一用户的对象的权限,则相应所有者的名称将作为授权者出现在 sp_helprotect 输出中。

    sp_helprotect 报告有关加密列、加密密钥及用户的相关信息,如下所示:

  • 表和列 – 报告授予了 decrypt 权限的表和列。

  • 加密密钥 – 报告已被授予 select 权限的加密密钥。

  • 用户 – 指示已授予 create encryption key 权限的用户。

    sp_helprotect 通过列出谓词特权的名称(如果有,将在输出中采用另一列列出)来报告谓词特权的相关信息。