Box Relatives

Thoughts about puzzles, math, coding, and miscellaneous

Viewing your permissions on SQL Server

| 0 comments

I wanted to see my permissions on SQL Server and Googling it was proving very hard. So I’m adding this here in case someone might find it useful. This will look at all the databases on the current server and list all of your permissions for each. As a bonus, it will list the current server as well.

DECLARE @myserver sysname;
SET @myserver = (
        SELECT 
        	s.name
        FROM
        	sys.servers s
        WHERE
        	s.server_id = 0
    );

SELECT 
	@myserver as 'Server'
,   d.name AS 'Database'
,   fbp.permission_name AS Permission
FROM
	(
	    SELECT 
	    	'DATABASE' AS mytype
	    ,   *
	    FROM
	    	sys.databases
	) d
       JOIN sys.fn_builtin_permissions(null) fbp
            ON  d.mytype = fbp.class_desc
WHERE
	Has_perms_by_name(quotename(d.name) , 'database' , fbp.permission_name) = 1
ORDER BY
	d.name

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.