MySQL 查询数据库中的所有表 生成每张表对应的SQL查询语句

原文:https://www.cnblogs.com/BenWong/p/3996061.html
原文:https://blog.csdn.net/zhouxukun123/article/details/80428378

为数据库中的每张表,都生成一条查询语句

最终效果:

原始数据

代码


select
	group_concat(
		concat('select * from ', table_name)
		 separator ';\r\n'
	) as col1
from information_schema.tables
where 1=1 
	and table_schema='wordpress1'
	and table_type='base table';
	group by table_schema

/* group_concat:将查询到的一列数据合并成字符串 */
/* separator:数据拼接时,指定的分隔符 */
/* concat:字符串拼接函数,相当于mssql里面的加号 */
/* table_schema:数据库名称 */

猜你喜欢

转载自www.cnblogs.com/guxingy/p/12742978.html