Execute the Following in the database context where you need to pull those permissions, This will create a sp_showpermissions stored procedure.
/****** Stored Procedure dbo.sp_showpermissions v 1.0 ******/
CREATE PROCEDURE sp_showpermissions
@group VARCHAR(30) = NULL
SET NOCOUNT ON
IF @group is NULL SELECT @group = 'public'
IF EXISTS (SELECT name from sysusers where name = @group and uid = gid)
SET NOCOUNT OFF
SELECT "ROLE NAME" = b.name,
"OBJECT NAME" = c.name,
"ACTION" = CASE a.action
WHEN 26 THEN 'REFERENCES'
WHEN 193 THEN 'SELECT'
WHEN 195 THEN 'INSERT'
WHEN 196 THEN 'DELETE'
WHEN 197 THEN 'UPDATE'
WHEN 198 THEN 'CREATE TABLE'
WHEN 203 THEN 'CREATE DATABASE'
WHEN 204 THEN 'GRANT_W_GRANT'
WHEN 205 THEN 'GRANT'
WHEN 206 THEN 'REVOKE'
WHEN 207 THEN 'CREATE VIEW'
WHEN 222 THEN 'CREATE PROCEDURE'
WHEN 224 THEN 'EXECUTE'
WHEN 228 THEN 'DUMP DATABASE'
WHEN 233 THEN 'CREATE DEFAULT'
WHEN 235 THEN 'DUMP TRANSACTION'
WHEN 236 THEN 'CREATE RULE'
"TYPE" = CASE c.type
WHEN 'C' THEN 'C CHECK constraint'
WHEN 'D' THEN 'D Default or DEFAULT constraint'
WHEN 'F' THEN 'F FOREIGN KEY constraint'
WHEN 'K' THEN 'K PRIMARY KEY or UNIQUE constraint'
WHEN 'L' THEN 'L Log'
WHEN 'P' THEN 'P Stored procedure'
WHEN 'R' THEN 'R Rule'
WHEN 'RF' THEN 'RF Stored procedure for replication'
WHEN 'S' THEN 'S System table'
WHEN 'TR' THEN 'TR Trigger'
WHEN 'U' THEN 'U User table'
WHEN 'V' THEN 'V View'
WHEN 'X' THEN 'X Extended stored procedure'
FROM sysprotects a, sysusers b, sysobjects c
WHERE a.uid = b.uid
AND c.id = a.id
AND b.name = @group
ORDER BY b.name, c.name, a.action
PRINT 'You did not provide a valid role name'
SELECT 'Valid role names for the ' + db_name() + ' database are:'
SELECT "Role Name"=name FROM sysusers WHERE uid = gid ORDER BY name
PRINT 'Syntax: sp_showpermissions [role_name]'
PRINT 'sp_showpermissions with no parameter will show permissions for public'
SET NOCOUNT OFF
Step 2: Next, Script out the execute of the above script and give parameter as a role name. Repeate this with all the Roles. And save the results in Excel, which will reduce the post work to be done.
Step 3: Next, Script the logins and roles using syslogins and sysusers, there is nothing you can be done here so everything is to be done normally. I’m not a TSQL Coder to code all this stuff. So, I had done all this manually and taken them in excel.
FYI, now we will be having following information related to permissions.
Logins and Roles associated.
Roles and Object Permissions
So we got the permissions.
Step 4: Proceed with the Restore using the following command,
LOAD DATABASE dbname
FROM disk = ‘......dat’
You will be done with the restoring the database, So now You need to proceed with the permissions.
Step 5: With the stuff you have got in Excel, make sure you change the stuff that will execute in the Query window. And then execute in the order, that will create the users for logins first and then object permissiosns to roles. So now thats it, You are done... Trust me... The above script is so handy....