title: SQL Server 2005: Wrapping Tables by Views - Pros and Cons
body: <h2>Background</h2>
  <p>I am working on a legacy small-business automation system (inventory, sales, procurement, etc.) that has a single database hosted by SQL Server 2005 and a bunch of client applications. The main client (used by all users) is an MS Access 2003 application (ADP), and other clients include various VB/VBA applications like Excel add-ins and command-line utilities.</p>
  <p>In addition to 60 or so tables (mostly in 3NF), the database contains about 200 views, about 170 UDFs (mostly scalar and table-valued inline ones), and about 50 stored procedures. As you might have guessed, some portion of so-called &quot;business logic&quot; is encapsulated in this mass of T-SQL code (and thus is shared by all clients).</p>
  <p>Overall, the system's code (including the T-SQL code) is not very well organized and is very refactoring-resistant, so to speak. In particular, schemata of most of the tables cry for all kinds of refactorings, small (like column renamings) and large (like normalization).</p>
  <p>FWIW, I have pretty long and decent application development experience (C/C++, Java, VB, and whatnot), but I am not a DBA. So, if the question will look silly to you, now you know why it is so. :-)</p>
  <h2>Question</h2>
  <p>While thinking about refactoring all this mess (in a peacemeal fashion of course), I've come up with the following idea:</p>
  <ol>
  <li><p>For each table, create a &quot;wrapper&quot; view that (a) has all the columns that the table has; and (b) in some cases, has some additional computed columns based on the table's &quot;real&quot; columns.</p>
  <p>A typical (albeit simplistic) example of such additional computed column would be sale price of a product derived from the product's regular price and discount.</p>
  </li>
  <li><p>Reorganize all the code (both T-SQL and VB/VBA client code) so that only the &quot;wrapper&quot; views refer to tables directly.</p>
  <p>So, for example, even if an application or a stored procedure needed to     insert/update/delete records from a table, they'd do that against the corresponding &quot;table wrapper&quot; view, not against the table directly.</p>
  </li>
  </ol>
  <p>So, essentially this is about <strong>isolating all the tables by views from the rest of the system</strong>.</p>
  <p>This approach seems to provide a lot of benefits, especially from maintainability viewpoint. For example:</p>
  <ul>
  <li><p>When a table column is to be renamed, it can be done without rewriting all the affected client code at once.</p>
  </li>
  <li><p>It is easier to implement derived attributes (easier than using computed columns).</p>
  </li>
  <li><p>You can effectively have aliases for column names.</p>
  </li>
  </ul>
  <p>Obviously, there must be some price for all these benefits, but I am not sure that I am seeing all the catches lurking out there.</p>
  <p>Did anybody try this approach in practice? What are the major pitfalls?</p>
  <p>One obvious disadvantage is the cost of maintaining &quot;wrapper&quot; views in sync with their corresponding tables (a new column in a table has to be added to a view too; a column deleted from a table has to be deleted from the view too; etc.). But this price seems to be small and fair for making the overall codebase more resilient.</p>
  <p>Does anyone know any other, stronger drawbacks?</p>
  <p>For example, usage of all those &quot;wrapper&quot; views instead of tables is very likely to have some adverse performance impact, but is this impact going to be substantial enough to worry about it? Also, while using ADODB, it is very easy to get a recordset that is not updateable even when it is based just on a few joined tables; so, are the &quot;wrapper&quot; views going to make things substantially worse? And so on, and so forth...</p>
  <p>Any comments (especially shared real experience) would be greatly appreciated.</p>
  <p>Thank you!</p>
  <hr />
  <p>P.S. I stepped on the following old article that discusses the idea of &quot;wrapper&quot; views:</p>
  <p><a href="http://www.craigsmullins.com/cnr_0299b.htm" rel="noreferrer">The Big View Myth</a></p>
  <p>The article advises to avoid the approach described above. But... I do not really see any good reasons against this idea in the article. Quite the contrary, in its list of good reasons to create a view, almost each item is exactly why it is so tempting to create a &quot;wrapper&quot; view for each and every table (especially in a legacy system, as a part of refactoring process).</p>
  <p>The article is really old (1999), so whatever reasons were good then may be no longer good now (and vice versa). It would be really interesting to hear from someone who considered or even tried this idea recently, with the latest versions of SQL Server and MS Access...</p>