首页 > 数据库 >SQL Server在所有表中查找

SQL Server在所有表中查找

时间:2022-08-15 14:12:52浏览次数:38  
标签:colName 表中 tableName Server rowCount SQL c1 t1 select

declare @Str nvarchar(max), @tableName varchar(50), @colName varchar(50), @rowCount int

select a.name tableName, b.name Colname, 0 as IsFound into #t1
from sysobjects a join syscolumns b on a.id=b.id join systypes c on b.xtype=c.xtype
where a.[type]='U' and c.name in ('varchar', 'nvarchar', 'char', 'nchar') --这里是设置字段的类型,以缩小范围

declare _c1 cursor for select Colname, tableName from #t1
open _c1
fetch next from _c1 into @colName, @tableName
while @@FETCH_STATUS=0 begin
--print @Str
select @Str='select @rowCount=count(1) from ['+@tableName+'] where ['+@colName+'] like ''%TotalDsc%''' --这里是要查找的内容
exec sp_executesql @Str, N'@rowCount int output', @rowCount output
if @rowCount>0 update #t1 set IsFound=1 where ColName=@colName and tableName=@tableName
fetch next from _c1 into @colName, @tableName
end
close _c1
deallocate _c1
select * from #t1 where IsFound=1
drop table #t1

 

标签:colName,表中,tableName,Server,rowCount,SQL,c1,t1,select
From: https://www.cnblogs.com/netCat/p/16588115.html

相关文章

  • Mysql 8.0报错
    安装更新源sudoapt-getupdate更新软件`sudoapt-getupgrade下载wgethttps://dev.mysql.com/get/mysql-apt-config_0.8.14-1_all.debsudodpkg-imysql-apt-con......
  • MySQL连接相关
    官网:https://dev.mysql.com/doc/refman/8.0/en/performance-schema-processlist-table.html   interactive_timeout:交互式连接超时时间(mysql工具、mysqldump等)wai......
  • sql2017 客户端中文
    结果发现不行,在ssms的语言选项(tool->option->international->lanuage)里面还是出不来简体中文。只好卸载了,重新下一个SSMS-Setup-CHS.exe;再安装ok了下载地址为:https://down......
  • 前端好用API之MutationObserver
    前情一直以来都没有好的方式可以监听元素变化,Mutationevents虽然可以监听DOM树结构变化,但是因性能问题和差的兼容问题(Webkit内核不支持)并不推荐使用。MutationObserver......
  • Failed to list *v1.CronJob: the server could not find the requested resource
    基础环境kubectlversionClientVersion:version.Info{Major:"1",Minor:"20",GitVersion:"v1.20.7",GitCommit:"132a687512d7fb058d0f5890f07d4121b3f0a2e2",GitTre......
  • SQL 序列生成器
    本篇介绍SQL:2016(ISO/IEC9075:2016)标准中定义的序列生成器(Sequencegenerator)和相关操作,以及六种主流数据库中的实现及差异:Oracle、MySQL、MicrosoftSQLServer、Postgre......
  • PostgreSQL之汉化pgAdmin4
    1.打开pgAdmin42.File—>Preferences3.看图......
  • 分析SQL瓶颈,SQL耗时
    原文链接:https://www.cnblogs.com/yidengjiagou/p/16587437.html1.查看Profile配置showvariableslike'%profil%';have_profiling表示是否支持profile功能,YES表......
  • CREATE LOGIN (Transact-SQL)
    CREATELOGIN(Transact-SQL)CreatesaloginforSQLServer,SQLDatabase,AzureSynapseAnalytics,orAnalyticsPlatformSystemdatabases.Clickoneofthefol......
  • Windows下postgresql安装步骤
    1.下载安装包官方下载链接本文示例postgresql-14.5-1-windows-x642.右键以管理员身份运行安装程序3.安装目录4.选择组件5.数据目录6.设置密码,默认超级用户postg......