0

I have a db with more than 1000s of stored procedures. Need a query to find the list of stored procedures which has public execute permission.

Query I tried which didn't give me clear output.

select name, 
    has_perms_by_name(name, 'OBJECT', 'EXECUTE') as has_execute,
    has_perms_by_name(name, 'OBJECT', 'VIEW DEFINITION') as has_view_definition
from sys.procedures
jarlh
  • 42,561
  • 8
  • 45
  • 63
sectest
  • 59
  • 5

1 Answers1

0

Not sure why you got voted down, seems like a reasonable question to me.

You'll need something along the lines of:

DECLARE @principal_id int

SELECT @principal_id = principal_id
  FROM sys.database_principals
 WHERE name = 'public'

SELECT o.name, 
       dp.permission_name,
       dp.state_desc
  FROM sys.objects o 
  JOIN sys.database_permissions  dp
    ON dp.class = 1
   AND dp.major_id = o.object_id
   AND dp.grantee_principal_id = @principal_id
   AND dp.type = 'EX' -- execute
   AND dp.state IN ('G', 'W')
 WHERE o.type = 'P' -- stored procedures
deroby
  • 5,902
  • 2
  • 19
  • 33