Hey, Can you please try Grant execute on function <> to <> where the initial bracket is the function name and the next one is for user name
GRANT EXECUTE on a Scalar-Valued Function Syntax
What is the syntax to GRANT EXECUTE ON FUNCTION for a Scalar-valued Function?
Thanks in advance for your help.
3 answers
Sort by: Most helpful
-
-
Erland Sommarskog 119.9K Reputation points MVP
2023-02-01T22:49:24.35+00:00 GRANT EXECUTE ON MyFun TO MyUser
Or exactly the same as for a stored procedure.
-
LiHongMSFT-4306 31,311 Reputation points
2023-02-02T02:17:21.3333333+00:00 Hi @Bobby P
What is the syntax to GRANT EXECUTE ON FUNCTION for a Scalar-valued Function?
You are almost here. As experts answered above, the syntax is simply like this:
GRANT EXECUTE ON [ufnXXXX] TO [user]
Also, if you want to quickly grant a user permission to all procedures or functions. Then you could try something like this:
SELECT 'GRANT ' + CASE(ROUTINE_TYPE) WHEN 'PROCEDURE' THEN 'EXECUTE ' WHEN 'FUNCTION' THEN CASE(DATA_TYPE) WHEN 'TABLE' THEN 'SELECT ' ELSE 'EXECUTE ' END END + 'ON [' + ROUTINE_SCHEMA + '].[' + ROUTINE_NAME + '] TO [user];' FROM INFORMATION_SCHEMA.ROUTINES WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),'IsMSShipped') = 0;
Note: The SELECT permission must be granted on this object rather than EXECUTE as for scalar functions.
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.