views:

1117

answers:

3

Is there a system stored procedure or a system view I can use?

+3  A: 

sp_helprotect [sic]

Ed Guiness
A: 

You can try something like this. Note, I believe 3 is EXECUTE.

SELECT
grantee_principal.name AS [Grantee],
CASE grantee_principal.type WHEN 'R' THEN 3 WHEN 'A' THEN 4 ELSE 2 END - CASE 'database' WHEN  'database' THEN 0 ELSE 2 END AS [GranteeType]
FROM
sys.all_objects AS sp
INNER JOIN sys.database_permissions AS prmssn ON prmssn.major_id=sp.object_id AND prmssn.minor_id=0 AND prmssn.class=1
INNER JOIN sys.database_principals AS grantee_principal ON grantee_principal.principal_id = prmssn.grantee_principal_id
WHERE
(sp.type = N'P' OR sp.type = N'RF' OR sp.type='PC')and(sp.name=N'myProcedure' and SCHEMA_N

I got that example by simply using SQL Profiler while looking at the permissions on a procedure. I hope that helps.

palehorse
A: 

In 7.0 or 2000, you can modify and use the following code:

SELECT convert(varchar(100),
        'GRANT ' +
        CASE         WHEN actadd & 32 = 32 THEN 'EXECUTE'
                ELSE
                        CASE WHEN actadd & 1 = 1   THEN 'SELECT' + CASE WHEN actadd & (8|2|16) > 0  THEN ', ' ELSE '' END ELSE '' END +
                        CASE WHEN actadd & 8 = 8   THEN 'INSERT' + CASE WHEN actadd & (2|16) > 0  THEN ', ' ELSE '' END ELSE '' END +
                        CASE WHEN actadd & 2 = 2   THEN 'UPDATE' + CASE WHEN actadd & (16) > 0  THEN ', ' ELSE '' END ELSE '' END +
                        CASE WHEN actadd & 16 = 16 THEN 'DELETE' ELSE '' END
        END + ' ON [' + o.name + '] TO [' + u.name + ']') AS '--Permissions--'
FROM syspermissions p
INNER JOIN sysusers u ON u.uid = p.grantee
INNER JOIN sysobjects o ON p.id = o.id
WHERE o.type <> 'S'
AND o.name NOT LIKE 'dt%'
--AND o.name = '<specific procedure/table>'
--AND u.name = '<specific user>'
ORDER BY u.name, o.name
Jonathan