Home All Groups Group Topic Archive Search About

sysobjects.xtype, sysdepends.depid and Views

Author
1 Sep 2005 4:00 PM
Saffron
I'm writing stored procedures to document tables. I want to be able to
list all the views that reference a table.

sp_help appears to provide this information but doesn't produce any
results even for tables I know to be referenced. The sp_help code looks
like this

   select distinct 'Table is referenced by views' = obj.name
   from sysobjects obj, sysdepends deps
   where obj.xtype ='V'
   and obj.id = deps.id
   and deps.depid = @objid
   and deps.deptype = 1 group by obj.name

For this procedure, @objid is the id of the table for which we are
getting the info.

After taking this apart and looking at the results, I get the correct
views as answers when I use the following where clause:

   sysdepends.depid=@objid
   and sysdepends.depid=sysobjects.id

For the results, sysobjects.xtype is 'U' and not 'V' which the MSDN
T-SQL reference would suggest is a user table (not a view), and the
sysdepends.deptype value is 0 and not 1.

Does anyone know of a reason why my views would have an xtype of 'U'
and not 'V'?
Why would the deptype value be not as the sp_help proc expects?

Confused!

-- Saffron

Author
1 Sep 2005 4:31 PM
John Bell
Hi

You may want to look at the INFORMATION_SCHEMA.VIEW_COLUMN_USAGE view.

John

Show quote
"Saffron" wrote:

>
> I'm writing stored procedures to document tables. I want to be able to
> list all the views that reference a table.
>
> sp_help appears to provide this information but doesn't produce any
> results even for tables I know to be referenced. The sp_help code looks
> like this
>
>    select distinct 'Table is referenced by views' = obj.name
>    from sysobjects obj, sysdepends deps
>    where obj.xtype ='V'
>    and obj.id = deps.id
>    and deps.depid = @objid
>    and deps.deptype = 1 group by obj.name
>
> For this procedure, @objid is the id of the table for which we are
> getting the info.
>
> After taking this apart and looking at the results, I get the correct
> views as answers when I use the following where clause:
>
>    sysdepends.depid=@objid
>    and sysdepends.depid=sysobjects.id
>
> For the results, sysobjects.xtype is 'U' and not 'V' which the MSDN
> T-SQL reference would suggest is a user table (not a view), and the
> sysdepends.deptype value is 0 and not 1.
>
> Does anyone know of a reason why my views would have an xtype of 'U'
> and not 'V'?
> Why would the deptype value be not as the sp_help proc expects?
>
> Confused!
>
> -- Saffron
>
>
Author
1 Sep 2005 5:51 PM
Alejandro Mesa
Take a look to sp_depends in [master] databse.


AMB

Show quote
"Saffron" wrote:

>
> I'm writing stored procedures to document tables. I want to be able to
> list all the views that reference a table.
>
> sp_help appears to provide this information but doesn't produce any
> results even for tables I know to be referenced. The sp_help code looks
> like this
>
>    select distinct 'Table is referenced by views' = obj.name
>    from sysobjects obj, sysdepends deps
>    where obj.xtype ='V'
>    and obj.id = deps.id
>    and deps.depid = @objid
>    and deps.deptype = 1 group by obj.name
>
> For this procedure, @objid is the id of the table for which we are
> getting the info.
>
> After taking this apart and looking at the results, I get the correct
> views as answers when I use the following where clause:
>
>    sysdepends.depid=@objid
>    and sysdepends.depid=sysobjects.id
>
> For the results, sysobjects.xtype is 'U' and not 'V' which the MSDN
> T-SQL reference would suggest is a user table (not a view), and the
> sysdepends.deptype value is 0 and not 1.
>
> Does anyone know of a reason why my views would have an xtype of 'U'
> and not 'V'?
> Why would the deptype value be not as the sp_help proc expects?
>
> Confused!
>
> -- Saffron
>
>
Author
2 Sep 2005 8:21 AM
Saffron
Thanks for your advice, found all the info I wanted in the
INFORMATION_SCHEMA.VIEW_COLUMN­_USAGE view.

-- Saffron

AddThis Social Bookmark Button