我想知道有权访问对称密钥的所有用户以及他们拥有的访问类型。你能告诉我怎么做吗?
答案 0 :(得分:3)
上面的答案实际上并不反映对象名称,请改为考虑:
select
[database] = db_name()
, u.name
, p.permission_name
, p.class
, p.class_desc
, ObjectNameForObjectORColumn
= object_name(p.major_id)
, objectNameActual
= case class_desc
when 'SYMMETRIC_KEYS' then sm.name
when 'CERTIFICATE' then [cert].name
end
, state_desc
from sys.database_permissions p
inner join sys.database_principals u
on p.grantee_principal_id = u.principal_id
left outer join sys.symmetric_keys sm
on p.major_id = sm.symmetric_key_id
and p.class_desc = 'SYMMETRIC_KEYS'
left outer join sys.certificates [cert]
on p.major_id = [cert].[certificate_id]
and p.class_desc = 'CERTIFICATE'
where class_desc in('SYMMETRIC_KEYS', 'CERTIFICATE')
order by u.name
更多https://danieladeniji.wordpress.com/2015/10/09/sql-server-list-permissions-for-user/
答案 1 :(得分:2)
也许这个查询可以提供帮助:
select u.name, p.permission_name, p.class_desc,
object_name(p.major_id) ObjectName, state_desc
from sys.database_permissions p join sys.database_principals u
on p.grantee_principal_id = u.principal_id
where class_desc = 'SYMMETRIC_KEYS'
答案 2 :(得分:0)
这个改进的查询提供了当前数据库的名称,以避免错误。此外,如果你使用SYMMETRIC KEYS,通常你也使用证书,那么为什么这也是查看CERTIFICATE权限的好选择:
select db_name(), u.name, p.permission_name, p.class_desc,
object_name(p.major_id) ObjectName, state_desc
from sys.database_permissions p join sys.database_principals u
on p.grantee_principal_id = u.principal_id
where class_desc in('SYMMETRIC_KEYS', 'CERTIFICATE')
order by u.name