- declare @str varchar(100)
- set @str='PH' --要搜索的字符串
- declare @s varchar(8000)
- declare tb cursor local for
- select s='if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'')
- print ''所在的表及字段: ['+b.name+'].['+a.name+']'''
- from syscolumns a join sysobjects b on a.id=b.id
- where b.xtype='U' and a.status>=0
- and a.xusertype in(175,239,231,167)
- open tb
- fetch next from tb into @s
- while @@fetch_status=0
- begin
- exec(@s)
- fetch next from tb into @s
- end
- close tb
- deallocate tb
全数据库各表中查找内容所在的字段位置
最新推荐文章于 2022-01-30 16:28:33 发布
本文介绍了一段 SQL Server 的 T-SQL 脚本,该脚本用于在所有表的所有字段中搜索指定字符串,并返回包含该字符串的表名和字段名。此脚本通过游标遍历系统表来实现跨表搜索。
257

被折叠的 条评论
为什么被折叠?



