日期:2014-05-18  浏览次数:20437 次

如何知道某个表被哪些存储过程或视图引用?
1如何知道某个表被哪些存储过程或视图引用?
2有1个字段中的内容但不知道表名和字段名,请教如何能搜索出该表名和字段名(好像某个牛人做过)

------解决方案--------------------
sp_depends
显示有关数据库对象相关性的信息(例如,依赖表或视图的视图和过程,以及视图或过程所依赖的表和视图)。不报告对当前数据库以外对象的引用。


------解决方案--------------------
--2.查全库是否有字符串 '你好 '
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