Return to Snippet

Revision: 39679
at January 19, 2011 22:13 by jatubio


Initial Code
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;

Initial URL


Initial Description
Can add columns to a table checking before if there

Initial Title
Add Column Table if not exists

Initial Tags
table

Initial Language
MySQL