SQL grant execute on multiple objects

感情迁移 提交于 2019-12-03 07:57:27

You cannot use wildcards - you have to grant either to all objects (or all objects in a schema) - or then you have to list all objects one by one.

What you might do is something like this - have SQL Server generate those statements for you:

SELECT
   p.Name,
   GrantCmd = 'GRANT EXECUTE ON OBJECT::' + p.name + ' TO [domain\user]'
FROM sys.procedures p
WHERE p.Name LIKE 'XU%'

This query will list all procedures that start with XU and create a column that contains the GRANT EXECUTE ON .... statement for that procedure.

Run this in SQL Server Management Studio, and then just copy the resulting GrantCmd column, paste it to a new window, and execute it there.

And if you really want to automate this, you could also turn this query into a cursor and then use dynamic SQL to automatically execute those resulting GrantCmd statements....

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!