1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| DELIMITER ;
drop procedure if exists ModifColumnUnlessExists;
delimiter //
create procedure ModifColumnIfExists(
IN dbName tinytext,
IN tableName tinytext,
IN fieldName tinytext
)
begin
IF EXISTS (
SELECT * FROM information_schema.COLUMNS
WHERE column_name=fieldName
and table_name=tableName
and table_schema=dbName
)
THEN
set @ddl=CONCAT('ALTER TABLE ',dbName,'.',tableName,
' CHANGE ',fieldName,' ',
'
Lieu_modif VARCHAR(32) NULL
');
prepare stmt from @ddl;
execute stmt;
END IF;
end;
//
DELIMITER ;
CALL ModifColumnIfExists('basename', 'tablename', 'colonne'); |