17Oct/080
Permissions Script
Let's get this blog thing started!
I sometimes find that appropriate permissions are not always assigned to stored procedures during creation. This usually occurs when a proc is scripted and re-deployed in a hurry, or when a non-DBA decides to play in my sandbox. I use this rather simple script to quickly find and grant all missing permissions.
DECLARE @schema_owner VARCHAR(20); SET @schema_owner = 'dbo'; SELECT [name] AS 'storedProcedure', 'Grant Execute On ' + @schema_owner + '.' + [name] + ' To [insertDatabaseRoleHere];' AS 'sqlCode' 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 = '[insertDatabaseRoleHere]' ) And [type] = 'P';
This is especially useful for when you have a common database role that all stored procedures need to belong to; for example, infrastructures that share role membership to allow applications to execute procs.
Tagged as: Permissions, T-SQL Scripts
Leave a comment
Categories
- Business Intelligence
- Internals
- Miscellaneous
- PASS
- Performance & Tuning
- Presentations
- SQL 2008
- SQL Tips
- Syndication
- T-SQL Scripts
Subscribe to my blog!
| Like what you see? Subscribe! |
![]() |
Around the Web
Recent Tweets
- @zippy1981 I'm actually using @RedGate SQL Compare right now. It's worth every penny. #sqlhelp #redgate
- +1 :) RT @onpnt: Very well said, Janice :) @JaniceCLee your blog if full of WIN http://bit.ly/aZ4wPR
- @SQLDBA You're flying out of Orlando so there's def the possibility of a better deal. But I wouldn't do it unless you're a morning person :)


