1

We have been asked to get a list of all tables within our SQL Server 2008 database, which have SELECT permission to a specific role. It would need to be in a query, because then we need to write a script that revokes that GRANT SELECT permission.

Thanks.

Craig
  • 18,074
  • 38
  • 147
  • 248

1 Answers1

2

This isn't an entire answer (and can't be - I don't have an SQL Server installation to fiddle with) but hopefully it will get you on the right track. It's executing a stored procedure.

USE yourDB;
GO
EXEC sp_table_privileges 
   @table_name = '%';

Within the results set, you'll be interested primarily in the third column, table_name, and the sixth column, privileges.

Source: MSDN: sp_table_privileges

In my mind, the next step - assuming this is the data you are looking for - would be to wrap this SQL statement with one that inserts the results of the EXEC statement into a temporary table which you can then slice and dice as needed. This endeavour is left as an exercise to the reader (nudge nudge). The third answer on this stack overflow question may be of some use in extending the query given above but as always, YMMV.

Community
  • 1
  • 1
chucksmash
  • 5,777
  • 1
  • 32
  • 41