How can I view all grants for an SQL Database?

前端 未结 5 926
无人共我
无人共我 2020-12-31 00:49

I am using SQL Server 2005, I want to find out what all the grants are on a specific database for all tables. It would also help to find out all tables where the delete gran

5条回答
  •  自闭症患者
    2020-12-31 01:32

    The given solution does not cover where the permission is granted against the schema or the database itself, which do grant permissions against the tables as well. This will give you those situations, too. You can use a WHERE clause against permission_name to restrict to just DELETE.

    SELECT 
        class_desc 
      , CASE WHEN class = 0 THEN DB_NAME()
             WHEN class = 1 THEN OBJECT_NAME(major_id)
             WHEN class = 3 THEN SCHEMA_NAME(major_id) END [Securable]
      , USER_NAME(grantee_principal_id) [User]
      , permission_name
      , state_desc
    FROM sys.database_permissions
    

    Also, db_datawriter would need to be checked for membership because it gives implicit INSERT, UPDATE, and DELETE rights, meaning you won't see it show up in the permission DMVs or their derivatives.

提交回复
热议问题