Script to copy the roles with permissions – SQL Server

The below script will copy the roles with permissions,  before executing on your database  change the role name.  copy and paste the results  and execute on the target database.

declare @DBRoleName varchar(40) = ‘role_name’

SELECT ‘GRANT ‘ + dbprm.permission_name + ‘ ON ‘ + OBJECT_SCHEMA_NAME(major_id) + ‘.’ + OBJECT_NAME(major_id) + ‘ TO ‘ + dbrol.name + char(13) COLLATE Latin1_General_CI_AS

from sys.database_permissions dbprm

join sys.database_principals dbrol on

dbprm.grantee_principal_id = dbrol.principal_id

where dbrol.name = @DBRoleName