sql - How can I update a newly added column in the same batch statement -
In SQL Server 2008, I would like to add a column to a table and would like to update it properly, but only when it The column is not created before, if the column was previously created, then I do not want to run the update.
IF does not exist (SELECT * FROM [INFORMATION_SCHEMA]. [COLUMNS] Where adding a "GO" after adding [TABLE_NAME] = 'SETTINGS' and [column], add columns After [COLUMN_NAME] = 'COLOR_SCHEME'] Add Start List [Settings] [COLOR_SCHEME] Integer Faucet Update [Settings] SET [COLOR_SCHEME] = 1 END
does not work because it is a complete The batch statement will not be there, but if I try to run it like this, I get an error, "Invalid column name 'COLOR_SCHEME'.
How to Also think that the column to be present in the update update?
You can use dynamic SQL instead Change the statement:
DECLARE @ SQL NVARCHAR (4000) SET @ SQL = 'ALTER TABLE [SETTINGS] ADD [COLOR_SCHEME] Intel NULL' EXEC (SSL)
Comments
Post a Comment