Last active
August 29, 2015 14:18
-
-
Save jrdmb/5d7bdce2757344b22e13 to your computer and use it in GitHub Desktop.
Sql Server database role members
This file contains hidden or 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
-- Database Role Members | |
SELECT Users.name AS UserName, Roles.name AS RoleName, | |
'EXEC sp_droprolemember '+QUOTENAME(Roles.name,'''')+','+QUOTENAME(Users.name,'''')+';' AS Drop_Script, | |
'EXEC sp_addrolemember '+QUOTENAME(Roles.name,'''')+','+QUOTENAME(Users.name,'''')+';' AS Add_Script | |
FROM sys.database_role_members RoleMembers | |
JOIN sys.database_principals Users | |
ON RoleMembers.member_principal_id = Users.principal_id | |
JOIN sys.database_principals Roles | |
ON RoleMembers.role_principal_id = Roles.principal_id | |
--WHERE Users.name LIKE '%MyUserName%' | |
--WHERE Roles.name LIKE '%DBRoleName%' | |
#tsql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment