Created
April 5, 2016 10:14
-
-
Save tekiegirl/67b49c78865408edbd540fe1aa4f19f3 to your computer and use it in GitHub Desktop.
Drop a column, using SQL, if it exists
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='myTable' and COLUMN_NAME='columnToDrop') | |
BEGIN | |
ALTER TABLE myTable drop COLUMN columnToDrop | |
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
CREATE TABLE myTable | |
( | |
Region VARCHAR (50), | |
[Date] DATETIME, | |
ProjectId VARCHAR (10), | |
columnToDrop VARCHAR (20), | |
) | |
GO | |
INSERT INTO myTable (Region,[Date],ProjectId,columnToDrop) | |
VALUES | |
('West','2009-03-01','10001','Orange'); | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment