Click here to Skip to main content
15,885,872 members
Articles / Database Development / SQL Server
Article

Grant Execute on all procedures to a user

Rate me:
Please Sign up or sign in to vote.
3.58/5 (11 votes)
14 Jan 2004 82.4K   323   20   5
This stored procedure grants execute privilege on all procedures to specified user

Introduction

Granting execute privileges on all procedures to a restricted user, can be an issue. However, by retrieving the meta data information from the sysobjects, a simple loop can emulate this process and grant the execute on all available procedures to a specified user.

SQL
CREATE PROC grants as
declare curse cursor for select name from sysobjects where type='P'

OPEN CURSE
declare @proc varchar(100)
declare @stmt nvarchar(200)

fetch next from curse into @proc
while @@fetch_status=0 
begin
set @stmt='grant execute on '+@proc+' to bnbuser'
exec SP_EXECUTESQL @STMT
print @stmt
fetch next from curse into @proc
end

close curse
deallocate curse

GO

After the compilation, just write grants in the query analyser to automate the grant process.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader EA
United States United States
Sumit Amar started programming in BASIC at the age of 14 in 1993, then moved on to C/UNIX.
Later in 1999, he started developing commercial applications in J2SE, J2EE and Perl. He started developing applications in .NET with ASP+ (later renamed to ASP.NET) in December 2000 with public Beta 1. He has been developing in .NET ever since.

He has an MBA degree in IT and Systems.

Sumit is a Director of Engineering at Electronic Arts, where he works on building hybrid cloud systems.

Comments and Discussions

 
QuestionBetter option Pin
Roger Willcocks20-Jul-11 17:03
Roger Willcocks20-Jul-11 17:03 
http://msdn.microsoft.com/en-us/library/ms188371.aspx

GRANT EXECUTE ON SCHEMA::dbo TO newrole

in SQL 2005 and up
Roger Willcocks
Software Engineer
MCP, MCSD .NET
http://www.l-space-design.com/

Generalgood one Pin
vikas amin14-Nov-08 6:51
vikas amin14-Nov-08 6:51 
General10x Pin
archimedes0929-Aug-08 0:54
archimedes0929-Aug-08 0:54 
GeneralThanks Pin
toxaq4-Jul-07 16:15
toxaq4-Jul-07 16:15 
Generalgrant execute Pin
Anonymous26-Aug-05 2:47
Anonymous26-Aug-05 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.