Copy SQL object permissions
Tagged:  •  

The following will generate the SQL statements for the specified role or user. In the example below, it generates all GRANT or REVOKE statements for the public role:

SELECT 
CASE protecttype
WHEN 205 then 'grant '
WHEN 206 then 'revoke '
END
+
CASE action
WHEN 26 then ' references '
WHEN 193 then ' select '
WHEN 195 then ' insert '
WHEN 196 then ' delete '
WHEN 197 then ' update '
WHEN 224 then ' execute '
END
+ ' ON ' +
object_name(id)
+ ' TO DESTINATIONE_ROLE ' +
CASE
WHEN protecttype = 204 THEN ' with grant option'
ELSE ''
END
FROM sysprotects
WHERE uid = user_id('public')
ORDER BY object_name(id)