码迷,mamicode.com
首页 > 数据库 > 详细

MySQL存储过程修改表存储引擎为InnoDB

时间:2015-07-12 15:56:42      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

第一次写存储过程,写得好憋屈。

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

标签:

原文地址:http://my.oschina.net/atanl/blog/477555

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!