Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Document Stored Procedures

Posted on 2007-12-05
7
Medium Priority
?
758 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
ID: 20412750
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
ID: 20412802
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
ID: 20429430
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

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

Author Comment

by:zebra06
ID: 20429610
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 2000 total points
ID: 20429694
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
ID: 20429711
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
What we learned in Webroot's webinar on multi-vector protection.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

877 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