Mysql sql

1.filter column which has number

select group_concat(table_name) from information_schema.tables where table_schema='db' and table_name REGEXP '[[:digit:]]';

 

 2.select multiple row into one row via group_concat() method

 

3.Filter column which has number, REGEXP '[0-9]'

select group_concat(table_name) from information_schema.tables where table_name REGEXP '[0-9]';

 

4.Drop table where table name has number

SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables  WHERE table_schema = 'db' AND table_name regexp '[0-9]';

 

 

DROP TABLE mt1,mt10,mt100,mt11,mt12,mt13,mt14,mt15,mt16,mt17,mt18,mt19,mt2,mt20,mt21,mt22,mt23,mt24,mt25,mt26,mt27,mt28,mt29,mt3,mt30,mt31,mt32,mt33,mt34,mt35,mt36,mt37,mt38,mt39,mt4,mt40,mt41,mt42,mt43,mt44,mt45,mt46,mt47,mt48,mt49,mt5,mt50,mt51,mt52,mt53,mt54,mt55,mt56,mt57,mt58,mt59,mt6,mt60,mt61,mt62,mt63,mt64,mt65,mt66,mt67,mt68,mt69,mt7,mt70,mt71,mt72,mt73,mt74,mt75,mt76,mt77,mt78,mt79,mt8,mt80,mt81,mt82,mt83,mt84,mt85,mt86,mt87,mt88,mt89,mt9,mt90,mt91,mt92,mt93,mt94,mt95,mt96,mt97,mt98,mt99;

 

 

5.Get table size in db

SELECT TABLE_NAME AS `Table`,  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM information_schema.TABLES WHERE TABLE_SCHEMA = "bookstore" ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC;

 

posted @ 2022-05-21 16:56  FredGrit  阅读(41)  评论(0编辑  收藏  举报