如何在所有表格中搜索单词。要输出所有可以使用此单词的表。
我使用IDEA进行查询。
问题是有300多个表。需要找到存在该词的表。
例如,有一个电话号码表,其中有一个数字列,我需要从数字列中找到一个值,例如3045636行
如何在所有表格中搜索单词。要输出所有可以使用此单词的表。
我使用IDEA进行查询。
问题是有300多个表。需要找到存在该词的表。
例如,有一个电话号码表,其中有一个数字列,我需要从数字列中找到一个值,例如3045636行
这是我建议的方法:
#Table Names
select table_name
from information_schema.tables
where table_type = 'base table' and table_catalog='dbname'
#Column Names
select column_name
from information_schema.columns
where table_name like 'table name'
#Word Search
select count(*) from table_name where column_name1 like 'searchWord' or column_name2 like 'searchWord'
所有这些事情都必须集成到过程中,所以最终如果count(*)> 1该表包含特定单词。
,解决方案1 您可以编写一个动态查询并使用循环。
在第一个循环中,获取所有表并加载所有字符串数据类型的列,并框住select查询并找到值,并将输出存储为中间表。
解决方案2 您可以使用Power Shell脚本。