Question

Is it possible, in .NET, to pass a sql statement to SQL server for parsing and return the tables involved in the statement and the type of operation. So for a statement like this :

select * from Table1
left outer join Table2 on Table1.id=Table2.foreignid;
delete from Table2 where date < 2009/12/12

SQL Server might return the tables involved like this :

Table1    Read
Table2    Read
Table2    Delete

So the statement isn't executed, it just returns the tables involved.

The reason I ask is that the application I am working on has application level table permissions that I want to apply on a table by table basis. The current method of parsing out the tables involved in a statement uses a regular expression and fails in anything other than simple statements. Obviously you can't really be using a regular expression for this kind of job

Was it helpful?

Solution

Would SET SHOWPLAN_ALL do it for you? It simulates the call query on the server and you may be able to parse the results.

Edit: It looks like SET SHOWPLAN_TEXT would be easier to parse.

OTHER TIPS

The reason I ask is that the application I am working on has application level table permissions that I want to apply on a table by table basis.

It seems to me you should create a database level role to capture those permissions, and apply them on that level. You paid for your database management system - don't spend your time coding what is best done by a solution that's already in place.

Application level permissions may make sense on the row level, and even those can be implemented at the database. But if they are on the table level, I don't see any excuse that justifies coding enforcement yourself. Use your database, you paid for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top