title: Add a non null column to a sql table script - getting an error
body: <p>SQL Server 2005.</p>
  
  <p>The following 3 lines of sql work without error if the Is_Active column had previously existed in the Dim_Form table.</p>
  
  <p>ie if Is_Active has not existed previously, running the following 3 lines gives an error as displayed below;</p>
  
  <pre><code>ALTER TABLE dbo.Dim_form add Is_Active bit NULL 
  UPDATE dbo.Dim_form set Is_Active = 1
  ALTER table dbo.Dim_form alter column Is_Active bit NOT NULL 
  </code></pre>
  
  <p>I get this error only if its a 'brand new' column</p>
  
  <pre><code>Msg 207, Level 16, State 1, Line 2
  Invalid column name 'Is_Active'.
  </code></pre>
  
  <p>If I run this</p>
  
  <pre><code>ALTER TABLE dbo.Dim_form add Is_Active bit NULL 
  GO
  
  UPDATE dbo.Dim_form set Is_Active = 1
  ALTER TABLE dbo.Dim_form alter column Is_Active bit NOT NULL 
  
  -- and now drop the newly created column
  ALTER TABLE dbo.Dim_form DROP COLUMN Is_Active
  </code></pre>
  
  <p>Now I can <em>run the original 3 lines of sql successfully</em> - any ideas what is happening with this?</p>
  
  <p>Why would the prior existence of a column have an effect on the script?</p>