1.mysql相關mysql
DROP PROCEDURE IF EXISTS pro_add_col; CREATE PROCEDURE pro_add_col(IN col varchar(255)) BEGIN DECLARE no_more_data INT DEFAULT 0; DECLARE tablename VARCHAR(255); DECLARE cur_tables CURSOR FOR select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='sal' and TABLE_NAME like 'sal_%'; DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_data = 1; OPEN cur_tables; FETCH cur_tables INTO tablename; REPEAT set @sql_alter_table = CONCAT('alter table ',tablename,' add ',col,' varchar(255)'); PREPARE pst FROM @sql_alter_table; EXECUTE pst; FETCH cur_tables INTO tablename; UNTIL no_more_data = 1 END REPEAT; CLOSE cur_tables; END; CALL pro_add_col('eno'); DROP PROCEDURE IF EXISTS pro_drop_col; CREATE PROCEDURE pro_drop_col(IN col varchar(255)) BEGIN DECLARE no_more_data INT DEFAULT 0; DECLARE tablename VARCHAR(255); DECLARE cur_tables CURSOR FOR select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='sal' and TABLE_NAME like 'sal_%'; DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_data = 1; OPEN cur_tables; FETCH cur_tables INTO tablename; REPEAT set @sql_alter_table = CONCAT('alter table ',tablename,' drop column ',col); PREPARE pst FROM @sql_alter_table; EXECUTE pst; FETCH cur_tables INTO tablename; UNTIL no_more_data = 1 END REPEAT; CLOSE cur_tables; END; CALL pro_drop_col('eno');