能不能全库查找某个表某个字段中包括特定关键字的记录?

robig 2018-11-07 11:35:00
我有一个数据库,里面10多张表,数据十来万条,里面的东西不熟悉。

现在我想找某个表中,某条记录,某个字段 为特定字符串或数字的 ,比如 '6693E96F-9398-4305-9045-E2332CE7F3B6'
能不能返回哪个表、记录 符合要求?
...全文
39 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
吉普赛的歌 2018-11-07
  • 打赏
  • 举报
回复
二月十六 版主 2018-11-07
  • 打赏
  • 举报
回复
declare @cloumns varchar(40)
declare @tablename varchar(40)
declare @str varchar(40)
declare @counts int
declare @sql nvarchar(2000)
declare MyCursor Cursor For
Select a.name as Columns, b.name as TableName from syscolumns a,sysobjects b,systypes c
where a.id = b.id
and b.type = 'U'
and a.xtype=c.xtype
and c.name like '%char%'
set @str='6693E96F-9398-4305-9045-E2332CE7F3B6'
Open MyCursor
Fetch next From MyCursor Into @cloumns,@tablename
While(@@Fetch_Status = 0)
Begin
set @sql='select @tmp_counts=count(*) from ' +@tablename+ ' where ' +@cloumns+' = ''' +@str+ ''''
execute sp_executesql @sql,N'@tmp_counts int out',@counts out
if @counts>0
begin332
print '表名为:'+@tablename+',字段名为'+@cloumns
end
Fetch next From MyCursor Into @cloumns,@tablename
End
Close MyCursor
Deallocate MyCursor

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧