zoukankan      html  css  js  c++  java
  • 91、mysql批量删除表

    ## 存储过程实现
    drop PROCEDURE if EXISTS rush;
    create PROCEDURE rush()
    BEGIN 
    
    ## 创建临时表,插入快照数据
    drop table if exists drop_tb;
    create TEMPORARY table drop_tb(
    rowNum int not null,
    table_name VARCHAR(50) not null
    );
    insert into drop_tb       
          select @r := @r + 1 as rowNum,
                 table_name
          from information_schema.TABLES as a,(select @r := 0 )as t
          where table_schema = (select DATABASE())
    			
          and table_name like 'c%' ##这个地方填写以什么开头的数据
          order by a.table_name ;
    
    ## 存储过程实现
    drop PROCEDURE if EXISTS rush;
    create PROCEDURE rush()
    BEGIN 
    
    ## 创建临时表,插入快照数据
    drop table if exists drop_tb;
    create TEMPORARY table drop_tb(
    rowNum int not null,
    table_name VARCHAR(50) not null
    );
    insert into drop_tb       
          select @r := @r + 1 as rowNum,
                 table_name
          from information_schema.TABLES as a,(select @r := 0 )as t
          where table_schema = (select DATABASE())
    			
          and table_name like 'c%' ##这个地方填写以什么开头的数据
          order by a.table_name ;
    
    ## 变量设置
    set @index = 0;
    set @count = (select count(0) from drop_tb) ;
    
    ## 遍历删除前缀为 aopi_copy 的表
    WHILE @index <  @count DO
            
        set @index = @index + 1 ;
        set @tb_name = (
            select table_name from drop_tb as ibn
            where ibn.rowNum = @index
          ) ;
        
        set @drop_sql_tax = concat('drop table if exists ',@tb_name); 
          
        PREPARE distSQL FROM @drop_sql_tax ;
        EXECUTE distSQL;
        DEALLOCATE PREPARE distSQL ;
    
    END WHILE;
    
    drop table drop_tb;
    
    end ;
    
    call rush();
    
    drop PROCEDURE if exists rush;
    
    ## THE END
    
    ## 变量设置
    set @index = 0;
    set @count = (select count(0) from drop_tb) ;
    
    ## 遍历删除前缀为 aopi_copy 的表
    WHILE @index <  @count DO
            
        set @index = @index + 1 ;
        set @tb_name = (
            select table_name from drop_tb as ibn
            where ibn.rowNum = @index
          ) ;
        
        set @drop_sql_tax = concat('drop table if exists ',@tb_name); 
          
        PREPARE distSQL FROM @drop_sql_tax ;
        EXECUTE distSQL;
        DEALLOCATE PREPARE distSQL ;
    
    END WHILE;
    
    drop table drop_tb;
    
    end ;
    
    call rush();
    
    drop PROCEDURE if exists rush;
    
    ## THE END
    

      

  • 相关阅读:
    二项分布和多项分布
    TF-IDF学习笔记(二)
    TF-IDF学习笔记(一)
    jieba中文分词
    爬虫利器3:Xpath语法与lxml库
    Python爬虫利器1:Requests库的用法
    Python爬虫实战一之爬取糗事百科段子
    Python中的逻辑运算符
    Python:闭包函数与装饰器
    Python:函数名称空间与作用域:
  • 原文地址:https://www.cnblogs.com/gfbzs/p/15588727.html
Copyright © 2011-2022 走看看