Last active
April 13, 2017 15:10
-
-
Save paschott/e76563c7dee8601856072da8e59caf7f to your computer and use it in GitHub Desktop.
TSQL Script DB Permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
state_desc + ' ' + permission_name + ' on ['+ ss.name + '].[' + so.name + '] | |
to [' + sdpr.name + ']' COLLATE LATIN1_General_CI_AS as [Permissions T-SQL] | |
FROM SYS.DATABASE_PERMISSIONS AS sdp | |
JOIN sys.objects AS so | |
ON sdp.major_id = so.OBJECT_ID | |
JOIN SYS.SCHEMAS AS ss | |
ON so.SCHEMA_ID = ss.SCHEMA_ID | |
JOIN SYS.DATABASE_PRINCIPALS AS sdpr | |
ON sdp.grantee_principal_id = sdpr.principal_id | |
UNION | |
SELECT | |
state_desc + ' ' + permission_name + ' on Schema::['+ ss.name + '] | |
to [' + sdpr.name + ']' COLLATE LATIN1_General_CI_AS as [Permissions T-SQL] | |
FROM SYS.DATABASE_PERMISSIONS AS sdp | |
JOIN SYS.SCHEMAS AS ss | |
ON sdp.major_id = ss.SCHEMA_ID | |
AND sdp.class_desc = 'Schema' | |
JOIN SYS.DATABASE_PRINCIPALS AS sdpr | |
ON sdp.grantee_principal_id = sdpr.principal_id | |
order by [Permissions T-SQL] | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment