Skip to content

Instantly share code, notes, and snippets.

@manojchowrasiya
Created February 16, 2017 06:51
Show Gist options
  • Save manojchowrasiya/fde9de92c00586da805b08c27eb0b91c to your computer and use it in GitHub Desktop.
Save manojchowrasiya/fde9de92c00586da805b08c27eb0b91c to your computer and use it in GitHub Desktop.

check if column already exits in table

IF NOT EXISTS( SELECT NULL
            FROM INFORMATION_SCHEMA.COLUMNS
           WHERE table_name = 'tablename'
             AND table_schema = 'db_name'
             AND column_name = 'columnname')  THEN
  ALTER TABLE `TableName` ADD `ColumnName` int(1) NOT NULL default '0';
END IF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment