What are my permissions?1
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.)
Category: Microsoft SQL Server, Settings, SQLServerPedia Syndication, System Functions and Stored Procedures, T-SQL | Tags: Microsoft SQL Server, security, system functions
One thought on “What are my permissions?”
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Love this! Thanks again.