-- set here the role name:
declare @RoleName varchar(50) = 'ROLE_NAME'
declare @RoleScript varchar(max)
SELECT @RoleScript = 'CREATE ROLE ' + @RoleName + char(13)
SELECT @RoleScript = @RoleScript + 'GRANT ' + prm.permission_name + ' ON ' + OBJECT_NAME(major_id) + ' TO ' + rol.name + char(13) COLLATE Latin1_General_CI_AS
FROM sys.database_permissions prm
JOIN sys.database_principals rol ON prm.grantee_principal_id = rol.principal_id
WHERE rol.name = @RoleName
PRINT @RoleScript
No comments:
Post a Comment