Skip to main content
improved language/formatting
Source Link
tinlyx
  • 3.7k
  • 14
  • 48
  • 79

With the following command I managed to get a more correct response :

SELECT state_desc
    ,permission_name
    ,'ON'
    ,class_desc
    ,SCHEMA_NAME(major_id)
    ,'TO'
    ,USER_NAME(grantee_principal_id)
FROM sys.database_permissions AS PERM
JOIN sys.database_principals AS Prin
    ON PERM.grantee_principal_id = Prin.principal_id
        AND PERM.class_desc = 'SCHEMA'

The thing is that Scott's answer I thingthink the link between sys.database_permissions and sys.database_principals is uncorrectincorrect. Why joining over major_idmajor_id since that represents the schema and not the grantee (principal).

But thanks Scott !! your answer helps a lot !

With the following command I managed to get a more correct response :

SELECT state_desc
    ,permission_name
    ,'ON'
    ,class_desc
    ,SCHEMA_NAME(major_id)
    ,'TO'
    ,USER_NAME(grantee_principal_id)
FROM sys.database_permissions AS PERM
JOIN sys.database_principals AS Prin
    ON PERM.grantee_principal_id = Prin.principal_id
        AND PERM.class_desc = 'SCHEMA'

The thing is that Scott's answer I thing the link between sys.database_permissions and sys.database_principals is uncorrect. Why joining over major_id since that represents the schema and not the grantee (principal).

But thanks Scott !! your answer helps a lot !

With the following command I managed to get a more correct response :

SELECT state_desc
    ,permission_name
    ,'ON'
    ,class_desc
    ,SCHEMA_NAME(major_id)
    ,'TO'
    ,USER_NAME(grantee_principal_id)
FROM sys.database_permissions AS PERM
JOIN sys.database_principals AS Prin
    ON PERM.grantee_principal_id = Prin.principal_id
        AND PERM.class_desc = 'SCHEMA'

The thing is that Scott's answer I think the link between sys.database_permissions and sys.database_principals is incorrect. Why joining over major_id since that represents the schema and not the grantee (principal).

But thanks Scott !! your answer helps a lot !

Source Link
Delta
  • 113
  • 2

With the following command I managed to get a more correct response :

SELECT state_desc
    ,permission_name
    ,'ON'
    ,class_desc
    ,SCHEMA_NAME(major_id)
    ,'TO'
    ,USER_NAME(grantee_principal_id)
FROM sys.database_permissions AS PERM
JOIN sys.database_principals AS Prin
    ON PERM.grantee_principal_id = Prin.principal_id
        AND PERM.class_desc = 'SCHEMA'

The thing is that Scott's answer I thing the link between sys.database_permissions and sys.database_principals is uncorrect. Why joining over major_id since that represents the schema and not the grantee (principal).

But thanks Scott !! your answer helps a lot !