##SELECT TABLE_NAME,TABLE_ROWS, CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'bdata' ORDER BY TABLE_ROWS DESC
##select count(*) from (SELECT TABLE_NAME,TABLE_ROWS, CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'bdata' ORDER BY TABLE_ROWS DESC) as temp;
/*
DELIMITER $$
drop procedure if exists deleteTables $$
--
-- 实例
-- 存储过程名为:delateTables
-- 参数:没有参数
--
create procedure deleteTables ()
begin
declare tablename varchar(255); -- 待删除的表的名称
declare done int default false;-- 遍历数据结束标志
declare continue handler for not found set done = true; -- 将结束标志绑定到游标
declare rs cursor for select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'bdata' and TABLE_ROWS<100; -- 声明游标来实现遍历记录
open rs; -- 打开游标
-- 开始循环
read_loop: LOOP
-- 提取游标里的数据,这里只有一个,多个的话也一样;
FETCH cur INTO a;
SELECT a;
-- 声明结束的时候
IF done THEN
LEAVE read_loop;
END IF;
-- 这里做你想做的循环的事件
END LOOP ;
-- 关闭游标
CLOSE cur;
end $$
DELIMITER ;
call deleteTables;
*/
delimiter $$
DROP PROCEDURE IF EXISTS deletetables $$
--
-- 实例
-- 存储过程名为:delateTables
-- 参数:没有参数
--
CREATE PROCEDURE deletetables ()
BEGIN
DECLARE tablename VARCHAR(255); -- 待删除的表的名称
DECLARE done INT DEFAULT FALSE;-- 遍历数据结束标志
DECLARE cur CURSOR FOR SELECT table_name FROM information_schema.tables WHERE table_schema = 'bdata' AND table_rows<100; -- 声明游标来实现遍历记录
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; -- 将结束标志绑定到游标
OPEN cur; -- 打开游标
-- 下面是利用游标执行循环的部分
-- 开始循环
READ_LOOP: LOOP
-- 提取游标里的tb_myisam数据,这里只有一个,多个的话也一样;
FETCH cur INTO tablename;
-- DROP TABLE tablename;
-- 声明结束的时候
IF done THEN
LEAVE READ_LOOP;
END IF;
-- 一些敏感操作
SELECT tablename;
SET @sqlstr=concat("drop table ", tablename);
prepare stmt from @sqlstr;
EXECUTE stmt;
deallocate prepare stmt;
END LOOP ;
-- 关闭游标
CLOSE cur;
END $$
delimiter ;
-- CALL deletetables;
create event if not exists event_deletetables_rowslessthan100
#select table_name,table_rows from information_schema.columns where table_schema = "ptimpdb" and table_name like'mkk_data_%' ORDER BY TABLE_ROWS DESC;
#select table_name from information_schema.columns where table_schema = "ptimpdb" and table_name like'mkk_data_%'group by table_name;
#select count(*) as res from (select table_name from information_schema.columns where table_schema = "pdb" and table_name like'mkk_data_%'group by table_name)
#select count(*) as res from mkk_data_10
##数据库查询表的结果
#SELECT TABLE_NAME,TABLE_ROWS, CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'pdb' AND TABLE_NAME LIKE'mkk_data_%' AND TABLE_ROWS < 100 ORDER BY TABLE_ROWS DESC;
#SELECT TABLE_NAME,TABLE_ROWS, CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'pdb' AND TABLE_NAME LIKE'mkk_data_%' AND TABLE_ROWS < 100 ORDER BY TABLE_ROWS DESC;
delimiter $$
DROP PROCEDURE IF EXISTS deletetables $$
--
-- 实例
-- 存储过程名为:delateTables
-- 参数:没有参数 deletetables
--
CREATE PROCEDURE deletetables ()
BEGIN
DECLARE tablename VARCHAR(255); -- 待删除的表的名称
DECLARE done INT DEFAULT FALSE;-- 遍历数据结束标志
DECLARE cur CURSOR FOR SELECT table_name FROM information_schema.tables WHERE table_schema = 'pdb' AND table_rows<100; -- 声明游标来实现遍历记录
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; -- 将结束标志绑定到游标