How to create SQL scripts to recreate grants on a database granted through a role?

DECLARE @role_name VARCHAR(100) DECLARE @member_name VARCHAR(100) DECLARE @rolescur CURSOR DECLARE @rolememberscur CURSOR DECLARE @loginname VARCHAR(100) DECLARE @username VARCHAR(100) DECLARE @logincur CURSOR PRINT '– Grant user access' SET @logincur = CURSOR FOR SELECT l.name, u.name FROM master..sysxlogins l, sysusers u WHERE l.sid = u.sid AND l.name <> 'sa' OPEN @logincur FETCH NEXT FROM @logincur INTO @loginname,…