Assign EXECUTE on all Stored Procedures

by Allan Svelmøe Hansen May 26, 2008 16:57

A little script for assigning EXECUTE (or which ever setting) on all user made stored procedures in a database for SQL Server 2005

DECLARE @USER VARCHAR(255)
SET @USER 'DATABASE_USER_HERE'

DECLARE sp_CURSOR CURSOR
FOR
SELECT 
name FROM sys.all_objects
WHERE is_ms_shipped 0
AND TYPE 'P'

DECLARE @Name VARCHAR(255)
OPEN sp_CURSOR
FETCH NEXT FROM sp_CURSOR INTO @Name

WHILE @@FETCH_STATUS BEGIN
 EXEC
('GRANT EXECUTE ON '@Name +' TO ' @USER)
 
FETCH NEXT FROM sp_CURSOR INTO @Name
END

CLOSE 
sp_CURSOR
DEALLOCATE sp_CURSOR

Bookmark and Share DotnetKicks dotnetshoutout

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen | Modified by Mooglegiant

About:
Allan Svelmøe Hansen

My real name is Allan Svelmøe Hansen.
I live in Denmark, where I work as a developer for hedal:kruse:brohus using SQL Server and the .NET framework since 2004.
My primary fields of expertise is back-end data integration, database design and optimization.


       View Allan Svelmøe Hansen's profile on LinkedIn     

Disclaimer

The opinions expressed herein are my own personal opinions and thoughts and does not represent my employers view in any way, nor are my results guaranteed for all situations.
Content is presented "as is", with no warranty.