Wednesday, April 02, 2008

Assign permissions to multiple Stored Procedures in mssql 2005

Enterprise Manager from SQL 2005 allowed us to easily manage the permissions of multiple stored procedures from one place. I don't know why but SQL Server Management Studio for Microsoft SQL server 2005 only allows to manage the permissions of one stored procedure at a time.


Here is a script that Pedro Cruz shared with me that will ease this task:

SELECT 'GRANT EXECUTE ON ' + name + ' TO [UTILIZADOR_RW] AS [dbo]'

FROM sysobjects

WHERE type = 'P'


running this script will generate the sql scripts that will assign permissions to all stored procedures. just need to take out the ones you don't want and run them.


The result is something like:


GRANT EXECUTE ON FirstInsertUser TO [UTILIZADOR_RW] AS [dbo]

GRANT EXECUTE ON SecondInsertUser TO [UTILIZADOR_RW] AS [dbo]

GRANT EXECUTE ON InsertSendToAFriend TO [UTILIZADOR_RW] AS [dbo]

GRANT EXECUTE ON sp_upgraddiagrams TO [UTILIZADOR_RW] AS [dbo]

GRANT EXECUTE ON sp_helpdiagrams TO [UTILIZADOR_RW] AS [dbo]

GRANT EXECUTE ON sp_helpdiagramdefinition TO [UTILIZADOR_RW] AS [dbo]

...etc

No comments: