Granting execute permission on all stored procedures in a certain database

大憨熊 提交于 2019-12-23 10:46:10

问题


As the title suggests, I need to grant the execute permission on every stored procedure in a database. We've moved from test to production and have less control over the production database.. and all of the imported stored procedures got zero permissions right now. An interesting thing to know is if there is any way to make sure all of the imported stored procedures get execute permissions from the beginning?

Thanks for any help.


回答1:


Generate the statements, then copy them and paste into query window to run them

select 'grant execute on ' + 
    QuoteName(specific_schema) + '.' +
    QuoteName(specific_name) + ' to someone'
from information_schema.routines
where routine_type='PROCEDURE'



回答2:


As well as granting permissions, you should consider schemas.

So your stored procs are named in the Procs schema

  • Procs.DoStuff
  • Procs.DoMoreStuff
  • Procs.WriteStuff

Then you can GRANT EXECUTE ON SCHEMA::Procs TO RoleWhatever. All stored procedures created in Procs then inherit EXECUTE permissions

RoleWhatever could be a support role in production but a developer role in other environments.




回答3:


You have to grant the execute permission on the schema and repeat if you've got multiple schemas

grant  execute on schema :: yourschema to username


来源:https://stackoverflow.com/questions/5109581/granting-execute-permission-on-all-stored-procedures-in-a-certain-database

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