|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 9:12 PM
Points: 1,034,
Visits: 2,611
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 3:00 PM
Points: 2,764,
Visits: 1,438
|
|
This might work a bit faster
DECLARE @ProcName sysname , @usercredentials sysname
set @procname='' set @usercredentials='Development'
WHILE @procname is not null begin SELECT @procname = min(name) FROM sysobjects WHERE xtype='P' and name > @procname and name not like 'dt_%'
IF @procname is not null BEGIN EXEC('GRANT EXECUTE ON ' + @procname+ ' TO ' + @usercredentials) PRINT 'Execute permissions granted on '+ @procname+ ' TO ' + @usercredentials END
END
LinkedIn Profile
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, May 29, 2009 4:40 AM
Points: 1,
Visits: 4
|
|
| Whatever happened to using a good old fashioned cursor?
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 10:04 AM
Points: 585,
Visits: 53
|
|
| Just to add that it's often much easier in multi-user environments where more than a couple of users need similar access to create a single role and grant permissions to the role, then you can just add the users to the role to save you time.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, April 19, 2011 1:27 AM
Points: 116,
Visits: 59
|
|
The code below will do the trick with only one line of code:
EXEC master..xp_execresultset N'SELECT ''GRANT EXEC ON '' + o.name + '' TO '' + ''my_user'' FROM sysobjects o WHERE xtype = ''P'' AND [name] NOT LIKE ''dt_%'' ', my_db
Just replace my_user and my_db with the correct values.
I posted some more nice examples on xp_execresultset my blog some time ago:
http://www.vandeputte.org/2005/10/xpexecresultset.html
Kind regards,
Frederik
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, September 15, 2008 12:02 PM
Points: 1,318,
Visits: 57
|
|
Yes I'm being picky but doesn't this belong in Scripts rather than articles? Terry
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 3:00 PM
Points: 2,764,
Visits: 1,438
|
|
"Good" and "cursor" in the same sentence.
"Old Fashioned" is OK, it implies that something has worked
LinkedIn Profile
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 10:04 AM
Points: 585,
Visits: 53
|
|
I can't agree more, there's no way that those 2 words should ever appear in the same sentence  Oh, wait, how about... "it's no good, he's used a cursor rather than doing it properly with set based logic" or "good, said the highly paid consultant, i see that they've used a cursor; i should be able to make things a little faster if you want to pay me some more money" (but only for 99.99999 % of cases)
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Monday, November 20, 2006 10:12 AM
Points: 78,
Visits: 1
|
|
This likely won't make any difference when looping through stored procedure names, but it should be noted that "_" is a wildcard, representing any one character. like 'dt_%' would be better written as like 'dt\_%' escape '\' to force the script to treat the underscore as itself. Otherwise, great script! Very useful.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, May 18, 2012 9:46 AM
Points: 320,
Visits: 12
|
|
I'd vote for creating the "executors" role, adding "execute" permission on all the SPs to that and then adding the user(s) in question to the "executors" role. Maybe "executors" would be a good addition to the model db. By the way, where's your defensive "is this a real login" check? Chalk it up to paranoia, if you like, but I'd have a test in there.
|
|
|
|