Mysql使用存储过程批量更新多张表结构

#ALTER TABLE rba_product_price_1 ADD COLUMN operate_level TINYINT(2) NOT NULL DEFAULT 1 COMMENT '操作级别';

delimiter $$
DROP PROCEDURE IF EXISTS `inout_param`$$
create procedure inout_param()

BEGIN

DECLARE i INT;
DECLARE table_name VARCHAR(20); 
DECLARE table_pre VARCHAR(20); 
DECLARE sql_text VARCHAR(2000); 
SET i=0;
SET table_name='';
SET table_pre='rba_product_price_';
SET sql_text='';

while i<129 do

SET @table_name = CONCAT(table_pre,i);
#SELECT @table_name;
SET @sql_text = CONCAT('ALTER TABLE ',@table_name,' ADD COLUMN operate_level TINYINT(2) NOT NULL DEFAULT \'1\' COMMENT \'操作级别\';');

SELECT @sql_text;

PREPARE stmt FROM @sql_text;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;  
SET i=i+1;

end while;

END
$$
delimiter ;

call inout_param()

你可能感兴趣的:(mysql)