2

我想获取给定数据库和给定模式中的表列表,这些表对给定用户没有更新权限。

我该怎么做?

4

1 回答 1

1

以下应该工作。

http://consultingblogs.emc.com/jamiethomson/archive/2007/02/09/SQL-Server-2005_3A00_-View-all-permissions--_2800_2_2900_.aspx

基于此,我修改了一个脚本并将对象类型描述添加到显示用户、对象、权限类型、权限表的列表中

因此您可以添加 where caluse 过滤到 user_table 对象,按用户和权限类型进一步过滤

declare @type_desc varchar(100)
declare @user varchar(100)


WITH    perms_cte as

(

        select USER_NAME(p.grantee_principal_id) AS principal_name,

                dp.principal_id,

                dp.type_desc AS principal_type_desc,

                p.class_desc,

                OBJECT_NAME(p.major_id) AS object_name,

                o.type_desc,

                p.permission_name,

                p.state_desc AS permission_state_desc

        from    sys.database_permissions p

        inner   JOIN sys.database_principals dp


        on     p.grantee_principal_id = dp.principal_id

        inner join sys.objects o

        on o.object_id =p.major_id

)

--users

SELECT p.principal_name,  p.principal_type_desc, p.class_desc, p.[object_name], p.type_desc,p.permission_name, p.permission_state_desc, cast(NULL as sysname) as role_name
--select *
FROM    perms_cte p

WHERE   principal_type_desc <> 'DATABASE_ROLE'

UNION

--role members

SELECT rm.member_principal_name, rm.principal_type_desc, p.class_desc, p.object_name, p.type_desc,p.permission_name, p.permission_state_desc,rm.role_name

FROM    perms_cte p

right outer JOIN (

    select role_principal_id, dp.type_desc as principal_type_desc, member_principal_id,user_name(member_principal_id) as member_principal_name,user_name(role_principal_id) as role_name--,*

    from    sys.database_role_members rm

    INNER   JOIN sys.database_principals dp

    ON     rm.member_principal_id = dp.principal_id

) rm

ON     rm.role_principal_id = p.principal_id

order by 1

另一个有用的链接 http://www.mssqltips.com/sqlservertip/2132/auditing-sql-server-user-and-role-permissions-for-databases/

于 2012-06-30T18:06:12.537 回答