I am writing a deployment script that
- Creates a new column with a default value of 0 and is Null-able
- UPDATE the column data where a certain condition is met
Also note that if I explicitly set the default value to 0 in a INSERT Statement I recieve the same error when I am UPDATING data-
ERROR MESSAGE –
Invalid column name ‘isConvertWithDivison’.
SQL I AM USING –
ALTER TABLE dbo.accountCurrencies
ADD isConvertWithDivison BIT NULL DEFAULT 0
UPDATE dbo.accountCurrencies SET isConvertWithDivison = 1 WHERE currencyName = 'USD'
INSERT dbo.accountCurrencies
( currencyName)
VALUES ( 'AUD'),( 'DKK'),( 'RUB'),( 'SEK')
Seems Obvious what is going on but how do I work around this?
I have tried this to get the new collumn commited to the database before I execute the data changes but still no luck.
BEGIN TRANSACTION
ALTER TABLE dbo.accountCurrencies
ADD isConvertWithDivison BIT NULL DEFAULT 0
COMMIT TRANSACTION
UPDATE dbo.accountCurrencies SET isConvertWithDivison = 1 WHERE currencyName = 'USD'
INSERT dbo.accountCurrencies
( currencyName)
VALUES ( 'AUD'),( 'DKK'),( 'RUB'),( 'SEK')
FYI – Running SQL 2008 R2
use GO after alter statement,