ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

SQL-反向-模糊查询-Demo

2022-05-20 18:03:44  阅读:52  来源: 互联网

标签:information name Demo 反向 SQL table TABLE SELECT schema


总结:SQL-反向-模糊查询-Demo

SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA=(SELECT DATABASE()) AND table_name 
NOT IN (SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA=(SELECT DATABASE()) AND table_name LIKE "%copy%" OR table_name LIKE "%bak%")

解析1:该 SQL查 所有 当前操作数据库的 表名

SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA=(SELECT DATABASE())

解析2: 该 SQL模糊查询(包含“copy”,以及 包含“bak”)的表名

SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA=(SELECT DATABASE()) AND table_name LIKE "%copy%" OR table_name LIKE "%bak%"

解析3: 该 SQL结合解析1和解析2的SQL,意思是,查所有表名,但不包含(NOT IN(解析2))解析2中的模糊查询结果集(子查询)

SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA=(SELECT DATABASE()) AND table_name 
NOT IN (SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA=(SELECT DATABASE()) AND table_name LIKE "%copy%" OR table_name LIKE "%bak%")

标签:information,name,Demo,反向,SQL,table,TABLE,SELECT,schema
来源: https://www.cnblogs.com/tabkey9/p/16293246.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有