I am using SQL Server 2008 R2. I need to list out all the stored procedures that a database user (MYUSER) has execute permission.
Also, I need to list out which are the stored procedures that the user does NOT have EXECUTE permission - but can read the script of the stored procedure
Is there any SQL statement or helper function for these purpose?
REFERENCE:
From Stored Procedure Properties, select the Permissions page. To grant permissions to a user, database role, or application role, select Search. In Select Users or Roles, select Object Types to add or clear the users and roles you want. Select Browse to display the list of users or roles.
Use [SP_Config] select name, has_perms_by_name(name, 'OBJECT', 'EXECUTE') as has_execute from sys. procedures where name = 'proc_putObjectTVP'; But running this seems to give value 1 even if i remove the EXECUTE permission manually on the database. >_<
Connect to the database. Click the Users & Groups folder, and locate the user you want to grant permissions to. Right-click the user, and select Copy from the popup menu. Locate the procedure you want to allow the user to execute, in the Stored Procedures folder.
Use HAS_PERMS_BY_NAME
:
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
To check the permission for a different user, use this:
use my_db;
EXECUTE AS user = 'my_user'
SELECT SUSER_NAME(), USER_NAME();
select name,
has_perms_by_name(name, 'OBJECT', 'EXECUTE') as has_execute
from sys.procedures
where name = 'myprocname';
revert;
Works for my SQL Server 2012.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With