火焰

valeb
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

SQL 查询某个表被哪些存储过程使用到

Posted on 2015-01-13 14:38  valeb  阅读(805)  评论(0编辑  收藏  举报
--1.查询某个表被哪些存储过程使用到 :
select distinct object_name(id) 
from syscomments 
where id in (select object_id from sys.objects where type ='P') 
and text like'%TableName%'

 
--2.查找那些过程对该表做了更新操作:
select distinct object_name(id) 
from syscomments 
where id in(select object_id from sys.objects where type ='P') 
and text like'%update tablename%'
  declare @start datetime
  declare @end datetime 
  select 
  @start= CONVERT(DATETIME,CONVERT(nvarchar(10),RankStartTime,112)),
  @end=CONVERT(DATETIME,CONVERT(nvarchar(10),RankEndTime,112))+1 
  from (select OptionName,OptionValue from  KeyValueTable where OptionName in ('RankStartTime','RankEndTime')) SourceTable  
  PIVOT (MAX(OptionValue) FOR OptionName IN (RankStartTime, RankEndTime))AS PivotTable