SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Limiting view to only work when called from a stored procedure


Limiting view to only work when called from a stored procedure

Author
Message
Andrew in WV
Andrew in WV
SSC-Enthusiastic
SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)

Group: General Forum Members
Points: 183 Visits: 1376
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
WHERE @@PROCID <> 0

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.)

Andrew

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.

--Andrew
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28217 Visits: 39955
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!

Lowell

--
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!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search