时间:2021-07-01 10:21:17 帮助过:4人阅读
第一次写存储过程,写得好憋屈。
set @c_db := (select database());
drop procedure if exists alter_tables_engine;
delimiter //
create procedure alter_tables_engine()
begin
declare db varchar(64);
declare done boolean default 0;
declare t varchar(64);
declare table_names cursor for
select table_name from information_schema.tables where table_schema = @c_db;
declare continue handler for sqlstate ‘02000‘ set done = 1;
open table_names;
repeat
fetch table_names into t;
set @stmt = concat(‘alter table ‘, t, ‘ engine = InnoDB‘);
prepare s from @stmt;
execute s;
deallocate prepare s;
until done end repeat;
close table_names;
end;
//
delimiter ;
call alter_tables_engine();
drop procedure if exists alter_tables_type;
最后提个问题,我还没有google到的,怎么unset之前已经定义过的用户变量呢?
MySQL存储过程修改表存储引擎为InnoDB
标签: