August 16, 2018 by Kenneth Fisher
Permissions are a common concern. One of the most frequent requests I get is I need X, Y and Z permissions. And all too often the conversation goes like this:
Dev: I need write permission to this database.
Me: Checks their current permissions.
Me: You already have that permission.
Dev: Oh, ok, thanks.
It would certainly make my life a lot easier if there was a way for people to check their own permissions. Oh wait, there is!
This handy dandy function will tell you what your effective permissions are for any given object. That means if you have SELECT permissions from one role, and INSERT from another then this will show that you have SELECT, INSERT permissions. Note: It does not tell you where those permissions come from. Just what you have.
Now, I said object. That object, among other things, could be a database object (sp, table, etc), schema, the server, or even a database. See the link above for the full list. The syntax is pretty simple:
SELECT * FROM sys.fn_my_permissions(‘[object name]’,'[object type]’)
Example using the system view sys.tables
SELECT * FROM sys.fn_my_permissions('sys.tables','object');
Last comment on this. I usually have sysadmin permissions so I have all the permissions, so why would I ever need to use this? One word.
If you impersonate someone, you can then use this same system function to look at their effective permissions. Which in the end, is one of the easiest/fastest ways to check permissions for a specific object. (See the conversation above.)