0
点赞
收藏
分享

微信扫一扫

SQL Server 全库筛选指定字符串操作记录

SQL Server 全库筛选指定字符串操作记录

过程描述:

  1. 获取所有表和字段:只要字符型字段,字符串一定是字符型,如果要查询其它的就按需选择字段,避免字段类型错误;
  2. 通过excel拼接生成sql:每个字段一条查询语句。
  3. 查询结果union all 拼接到一起。


获取所有表和字段名

SELECT t.name,c.name

FROM SYSOBJECTS t,SYSCOLUMNS c

WHERE t.xtype= 'U' AND t.id= c.id AND c.xusertype IN (

SELECT xusertype FROM SYSTYPES WHERE name IN ( 'char', 'varchar', 'text', 'nchar', 'nvarcha', 'ntext' ))

说明:只要字符型字段

SQL Server 全库筛选指定字符串操作记录_hive

导出到excel公式拼接sql语句

="select '"&A2&"' as tt,'"&B2&"' as cc,"&B2&" as jg from "&A2 &" where "&B2 &" like '%指定字符串%' union all"

SQL Server 全库筛选指定字符串操作记录_字符串_02

拿几行测试

select 'cms_archive' as tt,'title' as cc,title as jg from cms_archive where title like '%2022%' union all

select 'cms_archive' as tt,'subtitle' as cc,subtitle as jg from cms_archive where subtitle like '%2022%' union all

select 'cms_archive' as tt,'source' as cc,source as jg from cms_archive where source like '%2022%' union all

select 'cms_archive' as tt,'author' as cc,author as jg from cms_archive where author like '%2022%'

SQL Server 全库筛选指定字符串操作记录_字段_03

执行全部

执行可能会比较慢,需要多等一会。



举报

相关推荐

0 条评论