Categories
Scripts

Permission List

This script gives a detailed information about permission for users in a database. This output lists Object name, Schema name, user name and permission. This is compatible only to SQL 2000.

Script

CREATE TABLE #DBUSERS (DBNAME VARCHAR(50),USERNAME VARCHAR(50), MEMBERNAME VARCHAR(50), OBJECTNAME VARCHAR(100), PERMGRANTED VARCHAR(200), PERMDENIED VARCHAR(50),COLUMNPERM VARCHAR(10))
DECLARE @cmd NVARCHAR(4000) DECLARE @cmd1 NVARCHAR(4000)
SET @cmd = 'insert into #DBUSERS (DBNAME,USERNAME,MEMBERNAME) select s.name,a.name, b.name from ?..sysusers a, ?..sysusers b, ?..sysmembers c,master..sysdatabases s where a.uid = c.memberuid and c.groupuid = b.uid and s.name like ''?'''
SET @cmd1 = 'insert into #DBUSERS (DBNAME,USERNAME,OBJECTNAME,PERMGRANTED,PERMDENIED,COLUMNPERM) select s.name,a.name,c.name,b.actadd,b.actmod,case when (b.seladd is not null or b.selmod is not null or b.updadd is not null or b.updmod is not null or b.refadd is not null or b.refmod is not null) then ''Y'' else ''N'' end from ?..sysusers a, ?..syspermissions b, ?..sysobjects c,master..sysdatabases s where a.uid = b.grantee and b.[id] = c.[id] and b.grantee <> 0 and s.name like ''?'''
EXEC sp_MSforeachdb @command1 = @cmd,@command2 = @cmd1
SELECT DBNAME,USERNAME,MEMBERNAME,OBJECTNAME,
CASE PERMGRANTED WHEN 1 THEN 'SELECT'
WHEN 2 THEN 'UPDATE'
WHEN 3 THEN 'SELECT,UPDATE'
WHEN 4 THEN 'REFERENCES'
WHEN 5 THEN 'SELECT, REFERENCES'
WHEN 6 THEN 'UPDATE,REFERENCES'
WHEN 7 THEN 'SELECT,UPDATE,REFERENCES'
WHEN 8 THEN 'INSERT'
WHEN 9 THEN 'SELECT,INSERT'
WHEN 10 THEN 'UPDATE,INSERT'
WHEN 11 THEN 'SELECT,UPDATE,INSERT'
WHEN 12 THEN 'REFERENCES,INSERT'
WHEN 13 THEN 'SELECT,REFERENCES,INSERT'
WHEN 14 THEN 'UPDATE,REFERENCES,INSERT'
WHEN 15 THEN 'SELECT,UPDATE,REFERENCES,INSERT'
WHEN 16 THEN 'DELETE'
WHEN 17 THEN 'SELECT,DELETE'
WHEN 18 THEN 'UPDATE,DELETE'
WHEN 19 THEN 'SELECT,UPDATE,DELETE'
WHEN 20 THEN 'REFERENCES,DELETE'
WHEN 21 THEN 'SELECT,REFERENCES,DELETE'
WHEN 22 THEN 'UPDATE,REFERENCES,DELETE'
WHEN 23 THEN 'SELECT,UPDATE,REFERENCES,DELETE'
WHEN 24 THEN 'INSERT,DELETE'
WHEN 25 THEN 'SELECT,INSERT,DELETE'
WHEN 26 THEN 'UPDATE,INSERT,DELETE'
WHEN 27 THEN 'SELECT,UPDATE,INSERT,DELETE'
WHEN 28 THEN 'REFERENCES,INSERT,DELETE'
WHEN 29 THEN 'SELECT,REFERENCES,INSERT,DELETE'
WHEN 30 THEN 'REFERENCES,INSERT,DELETE'
WHEN 31 THEN 'SELECT,UPDATE,REFERENCES,INSERT,DELETE'
WHEN 32 THEN 'EXECUTE'
ELSE NULL END AS "PERMGRANTED",
CASE PERMDENIED WHEN 1 THEN 'SELECT'
WHEN 2 THEN 'UPDATE'
WHEN 3 THEN 'SELECT,UPDATE'
WHEN 4 THEN 'REFERENCES'
WHEN 5 THEN 'SELECT, REFERENCES'
WHEN 6 THEN 'UPDATE,REFERENCES'
WHEN 7 THEN 'SELECT,UPDATE,REFERENCES'
WHEN 8 THEN 'INSERT'
WHEN 9 THEN 'SELECT,INSERT'
WHEN 10 THEN 'UPDATE,INSERT'
WHEN 11 THEN 'SELECT,UPDATE,INSERT'
WHEN 12 THEN 'REFERENCES,INSERT'
WHEN 13 THEN 'SELECT,REFERENCES,INSERT'
WHEN 14 THEN 'UPDATE,REFERENCES,INSERT'
WHEN 15 THEN 'SELECT,UPDATE,REFERENCES,INSERT'
WHEN 16 THEN 'DELETE'
WHEN 17 THEN 'SELECT,DELETE'
WHEN 18 THEN 'UPDATE,DELETE'
WHEN 19 THEN 'SELECT,UPDATE,DELETE'
WHEN 20 THEN 'REFERENCES,DELETE'
WHEN 21 THEN 'SELECT,REFERENCES,DELETE'
WHEN 22 THEN 'UPDATE,REFERENCES,DELETE'
WHEN 23 THEN 'SELECT,UPDATE,REFERENCES,DELETE'
WHEN 24 THEN 'INSERT,DELETE'
WHEN 25 THEN 'SELECT,INSERT,DELETE'
WHEN 26 THEN 'UPDATE,INSERT,DELETE'
WHEN 27 THEN 'SELECT,UPDATE,INSERT,DELETE'
WHEN 28 THEN 'REFERENCES,INSERT,DELETE'
WHEN 29 THEN 'SELECT,REFERENCES,INSERT,DELETE'
WHEN 30 THEN 'REFERENCES,INSERT,DELETE'
WHEN 31 THEN 'SELECT,UPDATE,REFERENCES,INSERT,DELETE'
WHEN 32 THEN 'EXECUTE'
ELSE NULL END AS "PERMDENIED",COLUMNPERM FROM #DBUSERS WHERE DBNAME LIKE '%UKNOMIGDB2%' ORDER BY 1
DROP TABLE #DBUSERS

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*