среда, 18 августа 2010 г.

Список прав на объекты в текущей БД

DECLARE @Principal sysname
SET @Principal = NULL -- set this to a specific user or role name if desired.

SELECT
prin.name AS PrincipalName,
prin.type_desc AS PrincipalType,
CASE
WHEN perm.class=1 and perm.minor_id = 0 THEN 'OBJECT'
WHEN perm.class=1 and perm.minor_id = 0 THEN 'COLUMN'
ELSE perm.class_desc
END AS SecurableType,
sch.name AS SchemaName,
obj.name AS ObjectName,
IsNull(col.name,'') AS ColumnName,
state_desc AS PermissionState,
permission_name AS Permission
--,*
FROM sys.database_principals AS prin
JOIN sys.database_permissions AS perm
ON prin.principal_ID = perm.grantee_principal_ID
JOIN sys.objects AS obj
ON perm.major_id = obj.object_id
AND perm.minor_id = 0
LEFT JOIN sys.columns AS col
ON perm.major_id = col.object_id
AND col.column_id = perm.minor_id
JOIN sys.schemas AS sch
ON obj.schema_id = sch.schema_id
WHERE @Principal IS NULL OR prin.name=@Principal


Ссылка

Комментариев нет:

Locations of visitors to this page