Forked from kmoormann/IdempotentSQLAlterTableAddColumn.sql
Created
May 12, 2016 18:49
-
-
Save iho/e1ef71e2b9ca785f5a3a0a73c807527b to your computer and use it in GitHub Desktop.
Idempotent SQL Alter Table Statements
This file contains hidden or 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 hidden or 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