简体   繁体   中英

SQL cross referencing

If I was to make a change to an object(possibly a table), I want to find out via system catalog tables where this object is referenced/used. So what CatLog system table to check stored procedures? functions, triggers, constraints. Have I missed any?

Thanks for your help in advance, JemRug

to find the functions and procedures where a table is referenced, you can scan the routine_definition column of the sysibm.routines view for the table name. Use regexp_instr function to look for the pattern FROM|UPDATE|INSERT INTO followed by the table name.

with t1 as (                                                       
SELECT char(ROUTINE_SCHEMA,10) libname,                            
       char(ROUTINE_NAME,30) routine_name,                         
       cast(a.routine_definition as varchar(9999)) routine_defn    
FROM   sysibm.routines a                                           
where  routine_schema = 'YOURLIB'                                   
  ),  t2 as (                                                      
select  a.routine_name,                                            
   regexp_instr(a.routine_defn,                                    
        '(FROM|UPDATE|INSERT INTO)\s+YOUR_TABLE',1,1) pos,             
 a.routine_defn                                                    
from t1 a )                                                        
select  a.routine_name,  a.pos, substr(a.routine_defn,pos,20) text 
from      t2 a                                                     
where    a.pos > 0                                                 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM