Solved

Document Stored Procedures

Posted on 2007-12-05
7
745 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

821 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