Solved

Document Stored Procedures

Posted on 2007-12-05
7
743 Views
Last Modified: 2009-03-03
I am looking for a stored procedure or other method that will output the permissions on all stored procedures on my SQL server.  (I have both SQL2000 and SQL2005 instances).  I've been tasked with documenting all of our SQL servers (many) and want to do it more efficiently than pulling the property pages on each and seeing who has what.  I've found a great script that gives me SeverName, DB name, Role name and User Name w/ Id and want to create another loop to include stored procedures, the database name where it resides and the permissions on it.

Your help is appreciated!
0
Comment
Question by:zebra06
  • 4
  • 2
7 Comments
 
LVL 27

Expert Comment

by:ptjcb
Comment Utility
There is a system stored procedure

sp_helprotect

It returns information on the stored procedure if you use it as

sp_helprotect 'dbo.stored_procedure_name'

You could either use a cursor or another loop to insert each stored procedure name.

I do not know if this will also work with SQL 2000 databases. I don't have any to test : )

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Try to use attached query.

This is for SQL 2005 but should be similar for 2000

You can use sys views to query usefull information

Best Regards
FooKy




SELECT u.name,  s.name +'.'+ p.name, permission_name FROM sys.procedures p

JOIN sys.schemas s ON (p.schema_id = s.schema_id)

JOIN sys.database_permissions dp ON (dp.major_id = p.object_id)

JOIN sys.sysusers u ON (u.uid = dp.grantee_principal_id)

Open in new window

0
 

Author Comment

by:zebra06
Comment Utility
FooKy,

Great script for my 2005 instances but I really need to be able to do something similar on my 2k instances as well....I dont see any cooresponding objects to sys.procedures in sql2k.  I'll give partial credit to you for that script but Im still looking for one that does 2k as well......
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Give me 5 min
and I'll wrote it :) just need to logon. :D
0
 

Author Comment

by:zebra06
Comment Utility
Fooky, ptjcb's solution works on 2000, just have to write a cursor to get all of them from all databases running on the server.  I'm having a slight issue with yours though.  where do I  run this query?  What context?  (I know, I'm new at this and learning as fast as I can.)
0
 
LVL 11

Accepted Solution

by:
f_o_o_k_y earned 500 total points
Comment Utility
Hello,
This is only for Procedures.
If you want to list some other objects you must write some more WHEN acctadd ....... clausule :)
for every premision such as SELECT or INSERT there is different number in acctadd

This is also only for user procedures category =0  (this is not documented filed so im not sure about this.) so check if you have all your procedures if not then delete category = 0.

Best Regards
FooKy
SELECT o.name,u.name,

CASE 

 WHEN p.actadd = 32 and p.actmod = 0 THEN 'EXECUTE'

 WHEN p.actadd = 0 and p.actmod = 32 THEN 'DENY EXECUTE'

 WHEN p.actadd = 32 and p.actmod = 32 THEN 'EXECUTE WITH GRANT'

 ELSE 'THIS IS NOT A PROCEDURE'

END

FROM dbo.syspermissions AS p

JOIN dbo.sysobjects AS o ON (p.id=o.id)

JOIN dbo.sysusers AS u ON (u.uid=p.grantee)

WHERE  o.xtype = 'P' AND  o.category = 0

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Both scirpts should be run in each database.
Because in each database you have different users and can have objects with the same name :)
Best Regards
FooKy
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now