如何使用 TSQL 确定授予哪些角色对特定存储过程的执行权限?我可以使用系统存储过程或系统视图吗?
Ray Vega
问问题
4528 次
2 回答
1
在 7.0 或 2000 中,您可以修改和使用以下代码:
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
于 2008-09-16T07:30:12.590 回答
0
你可以尝试这样的事情。请注意,我相信 3 是执行。
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
我通过简单地使用 SQL Profiler 查看过程的权限来获得该示例。我希望这会有所帮助。
于 2008-09-15T21:56:52.640 回答