mysql数据库所有的表生成select count(*) 对应的sql语句

MySQL中获得所有表的名称:

mysql数据库所有的表生成select count(*) 对应的sql语句

MySQL语句中,‘mydata’是当前数据库的名称

information_schema.tables表示从表名中选择,information_schema.xxx中xxx可选的还有很多字段,如information_schema.columns表示从所有表的所有字段中选择。

MySQL字符串的连接使用concat函数,则按照要求可以有以下代码:

select concat("select count(*) from ",table_name,";") as cnts 
from information_schema.tables where table_schema='mydata';

得到结果:

mysql数据库所有的表生成select count(*) 对应的sql语句