高手请进:请问怎么在数据库所有表中查找一个指定值?

yyhandy 2006-12-16 08:05:22
请问怎么在数据库所有表中查找一个指定值?
...全文
389 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gc_ding 2007-02-09
  • 打赏
  • 举报
回复
--偶然发现这个贴子
--查整个数据库是否包括字符串“张三”
declare @str varchar(100)
set @str='张三'

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
bugchen888 2006-12-16
  • 打赏
  • 举报
回复
不知道要什么东西。。。
jackeyabc 2006-12-16
  • 打赏
  • 举报
回复
是的,用动态SQL语句,遍历所有的sysobjects中的表还有,所有syscolumns的字段,应该是可以的
只是这样效率不是很高
yyhandy 2006-12-16
  • 打赏
  • 举报
回复
marco08(天道酬勤) 麻烦兄弟给写一个好么?
marco08 2006-12-16
  • 打赏
  • 举报
回复
用动态SQL
yyhandy 2006-12-16
  • 打赏
  • 举报
回复
xiaoku 2006-12-16
  • 打赏
  • 举报
回复
什么意思?查询 所有表的 所有字段 ?

34,873

社区成员

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

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