SQL to get table names from view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jc1966
    New Member
    • Jun 2007
    • 1

    #1

    SQL to get table names from view

    How do I find out the table Name(s)/View Name(s) from which a view is created? For example, suppose a view XYZ_V was created from ABC_T and DEF_T tables. Now how do I know these 2 tables' name using SQL?
    Thanks
  • timhuck
    New Member
    • Jun 2007
    • 1

    #2
    Originally posted by jc1966
    How do I find out the table Name(s)/View Name(s) from which a view is created? For example, suppose a view XYZ_V was created from ABC_T and DEF_T tables. Now how do I know these 2 tables' name using SQL?
    Thanks
    Use catalog view SYSCAT.TABDEP. (In the DB2 catalog, view information is generally found in the same catalog views as tables).
    To just get tables that a view depends on you could use a query like
    Code:
    SELECT TD.BSCHEMA, TD.BNAME
    FROM SYSCAT.TABDEP TD
    WHERE   TD.BTYPE='T'
    AND TD.TABSCHEMA='<schema your view is in>'
    AND  TD.TABNAME='<your view name>'
    but a more general (and useful) query would join syscat.tables to tabdep, using tables.type='V' to report only views, and reporting all values of BTYPE. If you search the internet, you can probably find a nice CASE statement that will interpret TYPE and BTYPE to report expanded object types instead of the code letters.

    Comment

    Working...