SQL Server 2005.
The following 3 lines of sql work without error if the Is_Active column had previously existed in the Dim_Form table.
ie if Is_Active has not existed previously, running the following 3 lines gives an error as displayed below;
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
I get this error only if its a 'brand new' column
Msg 207, Level 16, State 1, Line 2
Invalid column name 'Is_Active'.
If I run this
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
Now I can run the original 3 lines of sql successfully - any ideas what is happening with this?
Why would the prior existence of a column have an effect on the script?