Created
September 20, 2012 20:47
-
-
Save kmoormann/3758257 to your computer and use it in GitHub Desktop.
Idempotent SQL Alter Table Statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IF EXISTS | |
( | |
SELECT * FROM [information_schema].[columns] | |
WHERE table_name = 'Customer' | |
AND table_schema = 'dbo' | |
AND column_name = 'FavoriteColorId' | |
) | |
BEGIN | |
ALTER TABLE [dbo].[Customer] | |
DROP COLUMN FavoriteColorId | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to Phil Haack for this...http://haacked.com/archive/2006/07/05/bulletproofsqlchangescriptsusinginformation_schemaviews.aspx