I am using a user which has read permission only. It basically has permission to
- Connect
- Execute
However, it does not have execute permissions on Functions and Stored Procedures. In part of my reports, I am calling my own functions. I would like to give my readonlyuser
permission to execute SP, Functions and Views.
I came across this code which shows how to give execute permission on Stored Procedures and Functions for a particular user.
- Grant Execute on all functions for testuser
declare @username varchar(255)
set @username = 'testuser'
SELECT 'grant exec on ' + QUOTENAME(ROUTINE_SCHEMA) + '.' +
QUOTENAME(ROUTINE_NAME) + ' TO ' + @username FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),'IsMSShipped') = 0
and ROUTINE_TYPE='PROCEDURE'
and for functions
declare @username varchar(255)
set @username = 'testuser'
SELECT 'grant exec on ' + QUOTENAME(ROUTINE_SCHEMA) + '.' +
QUOTENAME(ROUTINE_NAME) + ' TO ' + @username FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),'IsMSShipped') = 0
and ROUTINE_TYPE='FUNCTION'
Now, here it looks like this permission applied to existing SP and functions only. If you add a new function, you have to run this code again to grant permission.
Questions
If my above interpretation is not wrong, is there a way to give execute permission to a read only user so that you have permission on all functions and stored procedures, even if you create new functions?
Can I apply the same permissions on Views?
In this thread, it is said you cannot give execute permission on function which returns a table. Is that true?
I know there are a couple of questions but all of them are related. Better to be in one place.