Technical Article

To compare object permissions with 2 databases

,

Project are first developed on Development box then moved to Test and then to Prod. It may so happen that you find that things are working just fine on Test box
But in production an exception is being thrown. Some times this come from the fact that the permission is not set on the object correctly.Or the object may be missing
(like a table or stored proc)

This script will help us in comparing objects and permissions between same database
On two different servers.

select obj.name as 'OBJECT NAME',su.name as 'USER NAME',

'OBJECT TYPE' = CASE WHEN OBJ.XTYPE = 'P' THEN 'PROCEDURE'

            ELSE 'TABLE'

END,

 'SELECT' = case   when ( per.actadd&000001 > 0 AND obj.xtype = 'U') then  '1'

  else   '0' end ,

'UPDATE' = case when ( per.actadd&000010 > 0 AND obj.xtype = 'U' ) then '1'

else '0' end ,

 'DRI' = case when ( per.actadd&000100 > 0 AND obj.xtype = 'U') then '1'

else '0' end,

'INSERT' = case when ( per.actadd&001000 > 0 AND obj.xtype = 'U') then '1'

else '0' end ,

'DELETE' = case when ( per.actadd&010000 > 0 AND obj.xtype = 'U') then '1'

else '0' end,

'EXECUTE' = case when per.actadd&100000 > 0 then '1'

else '0' end

from sysobjects obj 

join syspermissions per on obj.id = per.id

join sysusers su on per.grantee = su.uid

where xtype IN ('U','P')

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating