﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / Strategies  / Limiting view to only work when called from a stored procedure / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 09:25:13 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Limiting view to only work when called from a stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic909671-49-1.aspx</link><description>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 [b]SELECT * FROM MillionRowTable [/b]against all the time just to see the table structure; that'd prevent any significant delays!</description><pubDate>Fri, 23 Apr 2010 10:44:57 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>Limiting view to only work when called from a stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic909671-49-1.aspx</link><description>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 [code="sql"]WHERE @@PROCID &amp;lt;&amp;gt; 0[/code] 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.)AndrewEdit: 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.</description><pubDate>Fri, 23 Apr 2010 10:41:10 GMT</pubDate><dc:creator>Andrew in WV</dc:creator></item></channel></rss>