Copy SQL object permissions
Submitted by Andy on Mon, 11/14/2005 - 01:00.
Tagged: SQL Server 2000
• T-SQL
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)
