Grant Execute Permission to a User on all non-system stored procedures

We could easily grant execute permission to a user on all stored procedures on a database as below.

USE 
GO
GRANT EXECUTE TO 
GO

But unfortunately, our database will be at risk since the user would have got access to almost all stored procedures including the system stored procedures in that database. Hence use below steps to grant access to non-system stored procedures securely.

  1. Run below script on the database and copy the output.
    • USE 
         GO
         SELECT 'EXEC(''GRANT EXECUTE ON 
            '+OBJECT_SCHEMA_NAME(object_id)+'.' + name + '
            TO []'')' 
            from sys.procedures ORDER BY name
         GO
      
  2. Paste the output to a new query window.
  3. Add “USE <database name>” at the beginning of the pasted output code and execute.

Note: Values inside ‘<‘ and ‘>’ has to be replaced with your actual database name and user information where ever required.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.