All Forums Database
HarshaKudumula 83 posts Joined 04/09
16 Dec 2013
RESERVED WORDS:Query to find Views and macros that reference a particular table or view

Hello Masters,
I am using the following view and macro to find the view/macros that refernce
a particular table or view but since it is a macro to pass parameters database
and tablename , it is really a manual effort and time consuming factor to
find the same across whole environment. Please let me know if there is any
better way to find it.
-----
REPLACE VIEW DBA.V_OBJ_DEPEND AS
SELECT DatabaseName,TVMName,TableKind,CreateText
FROM dbc.TVM T,dbc.dbase D
WHERE D.DatabaseId=T.DatabaseId
AND TableKind IN ('V', 'M')
UNION
SELECT DatabaseName,TVMName,TableKind,TextString
FROM dbc.TextTbl X,dbc.dbase D,dbc.TVM T
WHERE X.TextType='C'
AND X.DatabaseId=D.DatabaseId
AND X.TextId=T.TVMId
AND TableKind IN ('V', 'M');
--------------
REPLACE MACRO DBA.M_OBJ_DEPEND (db_nm CHAR(30) NOT NULL, tbl_nm CHAR(30) NOT NULL) AS (
WITH RECURSIVE dt_obj
(lvl, DatabaseName, TVMName, TableKind, dep_on_DatabaseName, dep_on_TVMName, dep_on_TableKind)
AS (
SELECT 0, DatabaseName, TVMName, TableKind, NULL (CHAR(30)), NULL (CHAR(30)), NULL (CHAR(1))
FROM dbc.TVM T,dbc.dbase D
WHERE D.DatabaseId=T.DatabaseId
AND DatabaseName=:db_nm
AND TVMName=:tbl_nm
UNION ALL
SELECT o.lvl + 1, txt.DatabaseName, txt.TVMName, txt.TableKind, o.DatabaseName, o.TVMName, o.TableKind
FROM DBA.V_OBJ_DEPEND txt, dt_obj o
WHERE txt.CreateText LIKE '%"' || TRIM(o.DatabaseName) || '"."' || TRIM(o.TVMName) || '"%' (NOT CS)
AND NOT (o.DatabaseName = txt.Databasename AND o.TVMName = txt.TVMName)
AND o.lvl + 1 < 30 /* Failsafe to prevent endless loop */
)
SEL lvl, DatabaseName, TVMName, TableKind, dep_on_DatabaseName, dep_on_TVMName, dep_on_TableKind
FROM dt_obj
ORDER BY 1, 2, 3;
);
---------
EXEC DBA.M_OBJ_DEPEND ('YourDatabaseName', 'YourTableName')

-------------

Thanks,
Reddy.

ulrich 816 posts Joined 09/09
16 Dec 2013

check
http://developer.teradata.com/blog/ulrich/2011/11/extract-and-analyse-database-object-dependencies

feel free to donate bitcoin:12kgAUHFUqvG2sQgaRBXFhCwyf9HXdkGud

HarshaKudumula 83 posts Joined 04/09
16 Dec 2013

Thank you, Ulrich.

You must sign in to leave a comment.