Skip to content

Instantly share code, notes, and snippets.

@tekiegirl
Created April 5, 2016 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekiegirl/67b49c78865408edbd540fe1aa4f19f3 to your computer and use it in GitHub Desktop.
Save tekiegirl/67b49c78865408edbd540fe1aa4f19f3 to your computer and use it in GitHub Desktop.
Drop a column, using SQL, if it exists
IF exists( select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='myTable' and COLUMN_NAME='columnToDrop')
BEGIN
ALTER TABLE myTable drop COLUMN columnToDrop
END
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