Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Limiting view to only work when called from a stored procedure Expand / Collapse
Posted Friday, April 23, 2010 10:41 AM



Group: General Forum Members
Last Login: Thursday, December 8, 2016 7:08 AM
Points: 137, Visits: 1,364
I have a rather long, complex view that should only be called from inside a stored procedure (one right now, possibly more later). Because it takes so long to execute without a WHERE clause, and since it should really only be used inside procedures that specify the necessary conditions, I want to make sure this view is never called directly. Setting the correct access rights will guarantee this for the most part, but I would like to even restrict ad hoc queries by someone with administrative access to the database.

To do this, I added the clause

to the end of the view definition. That way, if it is queried directly, it returns zero rows but it still returns the expected rows when called inside the procedure.

Other than documentation, are there other potential problems this might cause? Is this overkill?

(I know it needs to be documented, and that is an issue because it is too easy for someone to edit the view definition in the GUI and cause the comments to disappear.)


Edit: Ok, I tried. When I preview this it looks the way I want it, but when I view the actual post it converts the SQL inequality to HTML entities.

Post #909671
Posted Friday, April 23, 2010 10:44 AM



Group: General Forum Members
Last Login: Today @ 4:45 AM
Points: 14,557, Visits: 38,451
i actually can see how that is a good idea; some views pulling together a lot of stuff shouldn't be ad hoc queried;
I like the idea.
i might actually rename some tables and create views with the original name and add that feature;
I have some MillionRowTables that developers query SELECT * FROM MillionRowTable against all the time just to see the table structure; that'd prevent any significant delays!


help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #909672
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse