Friday, July 24, 2009

What Objects Have GRANTs to public?

This query returns any objects that have GRANTs to public.

In case you see them, my next post will be about the "dt_*" stored procedures.
SELECT
o.[type_desc] AS ObjType,
o.name,
dp.permission_name AS Perm
FROM sys.database_permissions AS dp
JOIN sys.objects AS o
ON dp.major_id = o.[object_id]
WHERE dp.grantee_principal_id = (
SELECT principal_id
FROM sys.database_principals
WHERE name = 'public'
)
AND dp.[state] = 'G'
AND o.name NOT LIKE 'MSmerge%'
AND o.name NOT LIKE 'sys%'
ORDER BY
o.[type_desc],
o.name,
dp.permission_name
Example Output:
ObjType     name   Perm
----------- ------ ----------
USER_TABLE t1 DELETE
USER_TABLE t1 INSERT
USER_TABLE t1 REFERENCES
USER_TABLE t1 SELECT
USER_TABLE t1 UPDATE
VIEW vw_t1 DELETE
VIEW vw_t1 INSERT
VIEW vw_t1 REFERENCES
VIEW vw_t1 SELECT
VIEW vw_t1 UPDATE

No comments:

Post a Comment