Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list of users and roles that have permissions to an object (table) in SQL

You'd think I'd be able to Google such a simple question. But no matter what I try, I hit a brick wall.

What is the TSQL statement to find a list of roles that have permissions to a table?

The pseudo-code looks like this:

SELECT role_name 
FROM permissions 
where object_name = 'the_table_i_need_to_know_about'
like image 223
Rabbi Avatar asked May 12 '11 16:05

Rabbi


People also ask

How do I get a list of users access to a table in SQL Server?

Under Object Explorer, expand the Databases directory and then, expand the required database that contains the table. Next, expand the Tables directory and right-click the required table for which you want to check permissions, and click on the “Properties” option.

How do I get a list of user roles in SQL Server?

To find all the role assignments to users in SQL Server database, you can use the following query. SELECT r.name role_principal_name, m.name AS member_principal_name FROM sys. database_role_members rm JOIN sys. database_principals r ON rm.

What are the permissions that a user can be granted on a database object?

An object-level privilege is a permission granted to an Oracle database user account or role to perform some action on a database object. These object privileges include SELECT, INSERT, UPDATE, DELETE, ALTER, INDEX on tables and views and EXECUTE on procedures, functions, and packages.


2 Answers

It's a bit tricky. First, remember that the built-in roles have pre-defined access; these won't show up in the query below. The proposed query lists custom database roles and which access they were specifically granted or denied. Is this what you were looking for?

select permission_name, state_desc, type_desc, U.name, OBJECT_NAME(major_id) 
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
like image 103
Herve Roggero Avatar answered Oct 05 '22 01:10

Herve Roggero


Try this,

sp_helprotect "table name" go

like image 41
sudmong Avatar answered Oct 05 '22 03:10

sudmong