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
- 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.