Scripting schema updates in MSSQL #1
This SQL statement will alter a table only if a column in the table to be altered does NOT contain a column named 'FavoriteColorId'.
From: http://haacked.com/
From: http://haacked.com/
IF NOT EXISTS ( SELECT * FROM [information_schema].[columns] WHERE table_name = 'Customer' AND table_schema = 'dbo' AND column_name = 'FavoriteColorId' ) BEGIN ALTER TABLE [dbo].[Customer] ADD FavoriteColorId int