views:

122

answers:

1

On SQL Server 2005, you're supposed to be able to find dependencies in Manglement Studio by right-clicking an object and choosing "View Dependencies". The dialog gives you a choice of "Objects that depend on this" (what I'm calling down-stream) or "Objects that this depends on" (up-stream).

Both directions seem to work adequately for Table objects, and View objects seem to report good information in the up-stream direction. The down-stream list for a View, however, appears to consist only of the View itself--even when I know that there are other dependents (in this case, another view).

Is there a way that I can find this information? I'm comfortable with writing queries against system tables if I have a clue about which to target....

+4  A: 

try:

sp_depends YourViewName

if you get no results, drop and recreate your view and try again. Dropping and recreating may work for the GUI but I didn't try there

this is a little slow (and not the best query), but give it a try:

DECLARE @Search  varchar(300)
SET @Search='yourViewName'
SELECT DISTINCT
    LEFT(so.name, 120) AS Object_Name,
    "object_type"=left(
          case so.type
     when 'U' then 'Table - User'
     when 'S' then 'Table - System'
     when 'V' then 'Table - View'
     when 'TR' then 'Trigger'
     when 'P' then 'Stored Procedure'
     when 'C' then 'Constraint - Check'
     when 'D' then 'Default'
     when 'K' then 'Key - Primary'
     when 'F' then 'Key - Foreign'
     when 'L' then 'Log'
     when 'R' then 'Rule'
     when 'RF' then 'Replication Filter stp'
     else '<<UNKNOWN '''+so.type+'''>>'
    end  -- case so.type
     ,50)
    FROM syscomments sc 
        INNER JOIN sysobjects so 
         ON so.id = sc.id
    WHERE
        text Like '%'+@Search+'%'
    ORDER BY 
        2,1
KM
Excellent script. One recommendation, you need to add 'TF' for User-Defined Function to your CASE list. Otherwise, the object_type comes back as "<<UNKNOWN 'TF>>". +1
ichiban
RolandTumble
@ichiban, this script predates 'TF' for User-Defined Function. I last updated when moving from sybase to sql server!
KM
@RolandTumble, I was able to see stored procedures that used views when I did sp_depends on views on my sql server 2005
KM
RolandTumble