Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Truncate/Alter Permission for a login

How to check whether a login has truncate permission for a particular table?

We have a login called Test for which we have given ALTER permission to particular tables alone. Now I want get the list of tables for which Test login has Alter permission.

Checked in google and forum couldn't find any answer.

like image 765
Pரதீப் Avatar asked Sep 19 '16 10:09

Pரதீப்


3 Answers

Assuming that you have the ability to impersonate the user, you can do the following:

execute as user = 'Test';

select p.*
from sys.tables as t
cross apply sys.fn_my_permissions(t.name, 'OBJECT') as p
    where permission_name = 'ALTER';

revert;
like image 164
Ben Thul Avatar answered Oct 05 '22 04:10

Ben Thul


If you wanted to list out the permissions against a particular user ,Try out with the below query.

SELECT  OBJECT_NAME(major_id) TableName,PERMISSION_NAME, STATE_DESC,  U.name UserName 
FROM sys.database_permissions P 
    JOIN sys.tables T ON P.major_id = T.object_id 
    JOIN sysusers U ON U.uid = P.grantee_principal_id
WHERE U.name='Test'

enter image description here

like image 23
Unnikrishnan R Avatar answered Oct 05 '22 03:10

Unnikrishnan R


You could use the following function as well to quickly check the permissions that are available for a specific user.

MS SQL Documentation that will give you some useful information on its usage is provided in the link.

Syntax:

SELECT * FROM sys.fn_my_permissions('TEST', 'USER');
like image 27
N00b Pr0grammer Avatar answered Oct 05 '22 04:10

N00b Pr0grammer