Skip to content

Instantly share code, notes, and snippets.

@jmlweb
Created February 20, 2012 15:52
Show Gist options
  • Save jmlweb/1869810 to your computer and use it in GitHub Desktop.
Save jmlweb/1869810 to your computer and use it in GitHub Desktop.
Verificar que no exista una columna antes de añadirla
DELIMITER $$
DROP PROCEDURE IF EXISTS add_has_detail_column $$
CREATE PROCEDURE add_has_detail_column()
BEGIN
IF NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME= 'events' AND COLUMN_NAME = 'has_detail') THEN
ALTER TABLE `events` ADD COLUMN `has_detail` BOOLEAN NOT NULL DEFAULT 1 AFTER `is_migrated`;
END IF;
END $$
CALL add_has_detail_column() $$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment