/ Published in: SQL
The sysprotects system table reports all of the permissions granted or denied in a given database. We'll need to join it with sysusers and sysobjects to get all the information we need. Here's an example query that only pulls information on objects (no CREATE TABLE permissions or anything else at the database level)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SELECT su.[name] AS 'User', CASE sp.[protecttype] WHEN 204 THEN 'GRANT w/ GRANT' WHEN 205 THEN 'GRANT' WHEN 206 THEN 'DENY' END AS 'Permission', CASE sp.[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 AS 'Action', so.[name] AS 'Object' FROM sysprotects AS sp INNER JOIN sysusers AS su ON sp.[uid] = su.[uid] INNER JOIN sysobjects AS so ON sp.[id] = so.[id] WHERE sp.[action] IN (26, 193, 195, 196, 197, 224) ORDER BY su.[name], so.[name];