In SQL Server 2008, I would like to add a column to a table and update it right after, but only if they column hasn't been created before. I do NOT want to run the update if the column has been created before.
IF NOT EXISTS (SELECT *
FROM [INFORMATION_SCHEMA].[COLUMNS]
WHERE [TABLE_NAME] = 'SETTINGS' AND [COLUMN_NAME] = 'COLOR_SCHEME')
BEGIN
ALTER TABLE [SETTINGS]
ADD [COLOR_SCHEME] int NULL
UPDATE [SETTINGS]
SET [COLOR_SCHEME] = 1
END
Putting a "GO" after the column add doesn't work because that wouldn't be a complete batch statement, but if I try to run it like this, i get the error, "Invalid column name 'COLOR_SCHEME'."
Any ideas on how to get the column to exist when the update is run?