/ Published in: MySQL
Can add columns to a table checking before if there
Expand |
Embed | Plain Text
delimiter '//' CREATE PROCEDURE addcol() BEGIN IF NOT EXISTS( SELECT * FROM information_schema.COLUMNS WHERE COLUMN_NAME='new_column' AND TABLE_NAME='usuarios' AND TABLE_SCHEMA='the_schema' ) THEN ALTER TABLE `the_schema`.`the_table` ADD COLUMN `new_column` BIGINT(20) UNSIGNED NOT NULL DEFAULT 1; END IF; END; // delimiter ';' CALL addcol(); DROP PROCEDURE addcol;
You need to login to post a comment.
