title: Catch Update/Insert Computed Column of a View
body: <p>I'm using SQL Server 2005/2008 R2</p>
  
  <p>My SQL script is:</p>
  
  <pre><code>UPDATE MyView 
  SET MyColumn = 'My new value' 
  WHERE ID = 7
  </code></pre>
  
  <p>The error message:</p>
  
  <blockquote>
    <p><em>Msg 271, Level 16, State 1, Line 1<br>
    The column "MyColumn" cannot be modified because it is either a computed column or is the result of a UNION operator.</em></p>
  </blockquote>
  
  <p>I know that <code>MyColumn</code> is a computed column from the base table (like when <code>FullName</code> is computed from <code>LastName + ', ' + FirstName</code>)</p>
  
  <p>My aim is to catch the error so the script keeps executing.</p>
  
  <p>I tried the following script with no luck. The error is not caught:</p>
  
  <pre><code>BEGIN TRY
      UPDATE MyView 
      SET MyColumn = 'My new value' 
      WHERE ID = 7
  END TRY 
  BEGIN CATCH
      -- Error occurred while updating view. The script will keep running
  END CATCH
  </code></pre>
  
  <p>I checked the following scripts trying to solve the problem, with no luck:</p>
  
  <p>Script 1</p>
  
  <pre><code>SELECT is_computed 
  FROM sys.columns c, sys.views v
  WHERE c.object_id = v.object_id
  AND v.name = 'MyView'
  </code></pre>
  
  <p>The previous script returns 0 for all results (which is not correct, one of the column is a computed column)</p>
  
  <p>Script 2:</p>
  
  <pre><code>SELECT * 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE table_name = 'MyView'`
  </code></pre>
  
  <p>Also I couldn't find any field from the returned script that has something to do with 'computed column' or 'result of a union' operation.</p>