<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Grant EXECUTE Permissions on all Stored Procedures to a Single User</title>
	<atom:link href="http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user/feed" rel="self" type="application/rss+xml" />
	<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user</link>
	<description>Jeremiah Peschka&#039;s ruminations on sql, ruby, c#, and other things</description>
	<lastBuildDate>Wed, 28 Jul 2010 14:05:12 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Lead Internet</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-738</link>
		<dc:creator>Lead Internet</dc:creator>
		<pubDate>Wed, 19 Aug 2009 04:07:33 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-738</guid>
		<description>Thanks Jeremiah. Very simple solution that saves alot of time and works without looping.</description>
		<content:encoded><![CDATA[<p>Thanks Jeremiah. Very simple solution that saves alot of time and works without looping.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Denis Gobo</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-180</link>
		<dc:creator>Denis Gobo</dc:creator>
		<pubDate>Mon, 26 Jan 2009 21:24:29 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-180</guid>
		<description>My version is here

http://wiki.lessthandot.com/index.php/Grant_Execute_Permissions_For_All_Stored_Procedures_To_A_User




--Grab all the procedures for the current DB
SELECT IDENTITY(INT,1,1) AS ID,
SPECIFIC_NAME
INTO #Procedurelist
FROM INFORMATION_SCHEMA.ROUTINES --Only Procs
WHERE OBJECTPROPERTY(OBJECT_ID(SPECIFIC_NAME),&#039;IsMSShipped&#039;) =0
AND ROUTINE_TYPE=&#039;PROCEDURE&#039;
ORDER BY SPECIFIC_NAME
 
DECLARE
@Loopid INT,
@MaxId INT,
@UserName VARCHAR(50)
 
 
--This is the user that will get the execute permissions
SELECT @UserName = &#039;SomeUser&#039;
 
 
--Grab start and end values for the loop
SELECT @Loopid = 1,
@MaxId = MAX(ID)
FROM #Procedurelist
 
DECLARE
@SQL VARCHAR(500),
@ProcName VARCHAR(400)
 
 
--This is where the loop starts
WHILE @Loopid &lt;= @MaxId BEGIN
 
--grab the procedure name
SELECT @ProcName = SPECIFIC_NAME
FROM #Procedurelist
WHERE ID = @Loopid
 
--construct the statement
SELECT @SQL = &#039;GRANT EXECUTE ON &#039; + @ProcName + &#039; TO &#039; + @UserName
PRINT (@SQL) --change PRINT to EXECUTE if you want it to run automatically
 
--increment counter
SET @Loopid = @Loopid + 1
END
 
--clean up
DROP TABLE #Procedurelist</description>
		<content:encoded><![CDATA[<p>My version is here</p>
<p><a href="http://wiki.lessthandot.com/index.php/Grant_Execute_Permissions_For_All_Stored_Procedures_To_A_User" rel="nofollow">http://wiki.lessthandot.com/index.php/Grant_Execute_Permissions_For_All_Stored_Procedures_To_A_User</a></p>
<p>&#8211;Grab all the procedures for the current DB<br />
SELECT IDENTITY(INT,1,1) AS ID,<br />
SPECIFIC_NAME<br />
INTO #Procedurelist<br />
FROM INFORMATION_SCHEMA.ROUTINES &#8211;Only Procs<br />
WHERE OBJECTPROPERTY(OBJECT_ID(SPECIFIC_NAME),&#8217;IsMSShipped&#8217;) =0<br />
AND ROUTINE_TYPE=&#8217;PROCEDURE&#8217;<br />
ORDER BY SPECIFIC_NAME</p>
<p>DECLARE<br />
@Loopid INT,<br />
@MaxId INT,<br />
@UserName VARCHAR(50)</p>
<p>&#8211;This is the user that will get the execute permissions<br />
SELECT @UserName = &#8216;SomeUser&#8217;</p>
<p>&#8211;Grab start and end values for the loop<br />
SELECT @Loopid = 1,<br />
@MaxId = MAX(ID)<br />
FROM #Procedurelist</p>
<p>DECLARE<br />
@SQL VARCHAR(500),<br />
@ProcName VARCHAR(400)</p>
<p>&#8211;This is where the loop starts<br />
WHILE @Loopid &lt;= @MaxId BEGIN</p>
<p>&#8211;grab the procedure name<br />
SELECT @ProcName = SPECIFIC_NAME<br />
FROM #Procedurelist<br />
WHERE ID = @Loopid</p>
<p>&#8211;construct the statement<br />
SELECT @SQL = &#8216;GRANT EXECUTE ON &#8216; + @ProcName + &#8216; TO &#8216; + @UserName<br />
PRINT (@SQL) &#8211;change PRINT to EXECUTE if you want it to run automatically</p>
<p>&#8211;increment counter<br />
SET @Loopid = @Loopid + 1<br />
END</p>
<p>&#8211;clean up<br />
DROP TABLE #Procedurelist</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Stasiuk</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-179</link>
		<dc:creator>Colin Stasiuk</dc:creator>
		<pubDate>Mon, 26 Jan 2009 20:10:42 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-179</guid>
		<description>CREATE ROLE db_executor
GRANT EXECUTE TO db_executor
EXEC sp_addrolemember &#039;db_executor&#039;, &#039;&lt;&gt;&#039;


This would work if you&#039;re looking to do it for all stored procedures.</description>
		<content:encoded><![CDATA[<p>CREATE ROLE db_executor<br />
GRANT EXECUTE TO db_executor<br />
EXEC sp_addrolemember &#8216;db_executor&#8217;, &#8216;&lt;&gt;&#8217;</p>
<p>This would work if you&#8217;re looking to do it for all stored procedures.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michelle Ufford</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-178</link>
		<dc:creator>Michelle Ufford</dc:creator>
		<pubDate>Mon, 26 Jan 2009 19:56:31 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-178</guid>
		<description>I love this trick!  Here&#039;s my version in case you&#039;re interested:

Declare @schema_owner varchar(20);
Set @schema_owner = &#039;dbo&#039;;

Select [name] As &#039;storedProcedure&#039;
    , &#039;Grant Execute On &#039; + @schema_owner + &#039;.&#039; + [name]
   + &#039; To [insertDatabaseRoleHere];&#039; As &#039;sqlCode&#039;
From sys.objects With (NoLock)
Where [name] Not In (
    Select o.name
    From sys.database_permissions p With (NoLock)
    Inner Join sys.objects o With (NoLock)
        On p.major_id = o.object_id
    Inner Join sys.database_principals u With (NoLock)
        On u.principal_id = p.grantee_principal_id
    Where u.name = &#039;[insertDatabaseRoleHere]&#039;
)
And [type] = &#039;P&#039;; 

There&#039;s a couple of differences between our scripts.  Your script is used to set up a brand new user, and mine is to check for missing permissions for an existing database role.  Also, you automatically execute, and mine you have to copy/paste/execute.  But overall, pretty much the same thing, just different ways to get there. :)</description>
		<content:encoded><![CDATA[<p>I love this trick!  Here&#8217;s my version in case you&#8217;re interested:</p>
<p>Declare @schema_owner varchar(20);<br />
Set @schema_owner = &#8216;dbo&#8217;;</p>
<p>Select [name] As &#8217;storedProcedure&#8217;<br />
    , &#8216;Grant Execute On &#8216; + @schema_owner + &#8216;.&#8217; + [name]<br />
   + &#8216; To [insertDatabaseRoleHere];&#8217; As &#8217;sqlCode&#8217;<br />
From sys.objects With (NoLock)<br />
Where [name] Not In (<br />
    Select o.name<br />
    From sys.database_permissions p With (NoLock)<br />
    Inner Join sys.objects o With (NoLock)<br />
        On p.major_id = o.object_id<br />
    Inner Join sys.database_principals u With (NoLock)<br />
        On u.principal_id = p.grantee_principal_id<br />
    Where u.name = &#8216;[insertDatabaseRoleHere]&#8216;<br />
)<br />
And [type] = &#8216;P&#8217;; </p>
<p>There&#8217;s a couple of differences between our scripts.  Your script is used to set up a brand new user, and mine is to check for missing permissions for an existing database role.  Also, you automatically execute, and mine you have to copy/paste/execute.  But overall, pretty much the same thing, just different ways to get there. <img src='http://facility9.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremiah Peschka</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-177</link>
		<dc:creator>Jeremiah Peschka</dc:creator>
		<pubDate>Mon, 26 Jan 2009 18:15:42 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-177</guid>
		<description>No worries, I can definitely see why you would prefer OBJECT_SCHEMA_NAME() over SCHEMA_NAME(). Special thanks to both John Keyes (twitter.com/jckeyes) and Brian Davis (twitter.com/brian78) for confirming that SCHEMA_NAME() works on SQL Server 2005 RTM and SP1.</description>
		<content:encoded><![CDATA[<p>No worries, I can definitely see why you would prefer OBJECT_SCHEMA_NAME() over SCHEMA_NAME(). Special thanks to both John Keyes (twitter.com/jckeyes) and Brian Davis (twitter.com/brian78) for confirming that SCHEMA_NAME() works on SQL Server 2005 RTM and SP1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Bertrand</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-176</link>
		<dc:creator>Aaron Bertrand</dc:creator>
		<pubDate>Mon, 26 Jan 2009 18:06:46 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-176</guid>
		<description>Sorry, as I tweeted, I am always using the newer function because many catalog views and dynamic management views/functions do not include schema_id.  And I&#039;d rather use the function than write out the joins by hand.  I&#039;m lazy.  And thankfully am not managing any pre-SP2 SQL Server 2005 instances.</description>
		<content:encoded><![CDATA[<p>Sorry, as I tweeted, I am always using the newer function because many catalog views and dynamic management views/functions do not include schema_id.  And I&#8217;d rather use the function than write out the joins by hand.  I&#8217;m lazy.  And thankfully am not managing any pre-SP2 SQL Server 2005 instances.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremiah Peschka</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-175</link>
		<dc:creator>Jeremiah Peschka</dc:creator>
		<pubDate>Mon, 26 Jan 2009 17:59:37 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-175</guid>
		<description>Very true, OBJECT_SCHEMA_NAME is a newer function. You can also use SCHEMA_NAME([schema_id]) to get the schema name on older releases of SQL Server 2005.</description>
		<content:encoded><![CDATA[<p>Very true, OBJECT_SCHEMA_NAME is a newer function. You can also use SCHEMA_NAME([schema_id]) to get the schema name on older releases of SQL Server 2005.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Bertrand</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-174</link>
		<dc:creator>Aaron Bertrand</dc:creator>
		<pubDate>Mon, 26 Jan 2009 17:26:51 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-174</guid>
		<description>Note that OBJECT_SCHEMA_NAME() requires 2005 SP2+, IIRC</description>
		<content:encoded><![CDATA[<p>Note that OBJECT_SCHEMA_NAME() requires 2005 SP2+, IIRC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Bertrand</title>
		<link>http://facility9.com/2009/01/26/grant-execute-permissions-on-all-stored-procedures-to-a-single-user#comment-173</link>
		<dc:creator>Aaron Bertrand</dc:creator>
		<pubDate>Mon, 26 Jan 2009 17:10:15 +0000</pubDate>
		<guid isPermaLink="false">http://facility9.com/?p=292#comment-173</guid>
		<description>Three suggestions:

(1) escape _ (otherwise it is treated as &quot;any single character&quot;)
(2) store the whole pattern in the string (that way if you move this to a procedure you don&#039;t have to change the procedure to support LIKE &#039;%[_]foo&#039; etc.)
(3) QUOTENAME() object names and include schema prefix in output

SET @sproc_name_pattern = N&#039;sproc[_]%&#039;;

SELECT @sql = @sql N&#039;GRANT EXECUTE ON &#039;
              + QUOTENAME(OBJECT_SCHEMA_NAME([object_id])) + &#039;.&#039;
              + QUOTENAME([name])
              + &#039; TO &#039;
              + QUOTENAME(@user_name)
              + &#039;;&#039;
              + @newline + @newline
  FROM sys.procedures
 WHERE [name] LIKE @sproc_name_pattern;</description>
		<content:encoded><![CDATA[<p>Three suggestions:</p>
<p>(1) escape _ (otherwise it is treated as &#8220;any single character&#8221;)<br />
(2) store the whole pattern in the string (that way if you move this to a procedure you don&#8217;t have to change the procedure to support LIKE &#8216;%[_]foo&#8217; etc.)<br />
(3) QUOTENAME() object names and include schema prefix in output</p>
<p>SET @sproc_name_pattern = N&#8217;sproc[_]%&#8217;;</p>
<p>SELECT @sql = @sql N&#8217;GRANT EXECUTE ON &#8216;<br />
              + QUOTENAME(OBJECT_SCHEMA_NAME([object_id])) + &#8216;.&#8217;<br />
              + QUOTENAME([name])<br />
              + &#8216; TO &#8216;<br />
              + QUOTENAME(@user_name)<br />
              + &#8216;;&#8217;<br />
              + @newline + @newline<br />
  FROM sys.procedures<br />
 WHERE [name] LIKE @sproc_name_pattern;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
