Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

Add Execute permission to a user.

I have 90 stored procedures and I would like to  grant  an EXECUTE permission to a user instead of manually doing it one by one.
What sql syntax or way to do it.
Avatar of Megan Brooks
Megan Brooks
Flag of United States of America image

There is no general execute permission that I am aware of, but you can assign execute permissions to a schema, which is then inherited by all SPs belonging to that schema.
Avatar of Shaun Kline
In conjunction with your other question, you can query the INFORMATION_SCHEMA to generate SQL for granting the permissions on all SP:
SELECT 'GRANT EXECUTE ON ' + ROUTINE_NAME + ' TO <USER>'
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
ORDER BY ROUTINE_NAME

Open in new window

Avatar of zachvaldez

ASKER

What is the ROUTINE NAME ? Is it the stored procedure?
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Does this statement apply to one SP on execution only? What if you have 90 SPs?  What is the routine to get into each one and add the permission to a user?
That's precisely the reason for assigning execute permission by schema instead of individually. You may need to move the SPs that you want to enable this way to their own schema, to avoid opening up access to other existing SPs that these users should not be able to execute. Or create new SPs in a new schema that simply call the other SPs in the original schema.
This query creates a row for each stored procedure in your database. You can then copy the results into another query window and run it.
OK, Megan I'm not familiar with your approach. First, I'd like to know how to create a schema to separate  or move the SPs  other than where they are now.

Shaun, if I understand correctly by reading and not applying yet I t appears that your solution  is two-step. Whatever the results are in the output, then copy and paste to a new query window and this will ultimately be the answer.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
/* CREATE A NEW ROLE */
CREATE ROLE db_executor

/* GRANT EXECUTE TO THE ROLE */
GRANT EXECUTE TO db_executor

For more information have a look: https://stackoverflow.com/questions/9321334/grant-execute-to-all-stored-procedures
THANKS