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:數據庫名稱 */


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM