0

There are approx 500 sprocs in my SQLSERVER 2000 database; each sproc has a typical Grant Execute statement similar to the following.

GRANT EXECUTE ON [dbo].[sproc_name]
TO [role1], [role2], [role3], [role4], etc...

How to view the names of the sprocs which have grant to a particular role and only that particular role exclusively.

For example, i DO NOT want role1 in combination with role2, or role3, i just want to view the ones where only role1 by itself has execute permission.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
joedotnot
  • 4,810
  • 8
  • 59
  • 91
  • @Mitch: ServerFault if anywhere, but it's also programming related in sone ways – gbn Dec 13 '09 at 07:54
  • My interest in this question is purely programming related. The GUI program calls stored procs, users belongs to roles. I the programmer have to program the stored procs, and work out what permissions to grant! – joedotnot Dec 14 '09 at 02:38

2 Answers2

1

This is for SQL Server 2000:

SELECT
    OBJECT_NAME(p1.id)
FROM
    syspermissions p1
WHERE
    USER_NAME(p1.grantee) = 'MyRole'
    AND
    OBJECT_NAME(p1.id) = 'MyProc'
    AND
    NOT EXISTS (SELECT *
        FROM
            syspermissions p2
        WHERE
            p1.grantee <> p2.grantee
            AND
            p1.id = p2.id)
gbn
  • 422,506
  • 82
  • 585
  • 676
  • Essentially what i was looking for! Thanks so much. (Incidentally the 'MyProc' should not be in the where clause, as we want a list of sprocs). My modified answer below, but essentially you get the credit. – joedotnot Dec 14 '09 at 02:23
1

Based on the answer by gbn. This is more appropriate, but essentially he provided the answer.

-- show all stored procs where permission is granted to 'MyRole' and only 'MyRole'
SELECT OBJECT_NAME(p1.id) AS sproc_name
  FROM    syspermissions p1
  inner join sysobjects o ON p1.id = o.id
    AND o.xtype = 'p'
    AND o.[name] not like 'dt_%'
WHERE USER_NAME(p1.grantee) = 'MyRole'
AND NOT EXISTS (
        SELECT *        
            FROM  syspermissions p2        
        WHERE p1.grantee <> p2.grantee            
        AND p1.id = p2.id
    )
ORDER BY 1
joedotnot
  • 4,810
  • 8
  • 59
  • 91