Assign EXECUTE on all Stored Procedures

by ASH 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

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading



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

About me

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. But I also work with website development as well as application/services for server and SEO of websites.

Disclaimer

The opinions expressed herein are my own personal opinions and thoughts and does not represent my employer's view in any way, nor are my results guarentees for all situations.

Content is presented “as is”, with no warranty.