Finding all child tables

How can i find all the the child tables of a table? Is there an SQL query in Oracle by which i could get this info?

Hi,
select table_name, constraint_type
  from user_constraints
where R_CONSTRAINT_NAME=  (select constraint_name
                                                     from user_constraints
                                                 where table_name = 'PARENT' and constraint_type = 'P')
   and constraint_type = 'R';Regards

Similar Messages

  • Query ---  to find all child tables for a master table

    Suppose i have a table master .
    I want to know all tables which are child tables for this master table .
    In other words i want to know all those table names which have foreign key constraint for the master table .
    regards
    shubha

    You may want to join on the owner in case you have multiple schemas with same table names and same primary key names
    SELECT c.table_nameFROM all_constraints c, all_constraints p
    WHERE c.constraint_type = 'R'
    AND c.r_constraint_name = p.constraint_name
    AND p.constraint_type = 'P'
    AND c.owner = p.owner
    AND p.table_name = '&YOUR_MASTER_TABLE'

  • Find all child tables - validate sql

    I have a table (tabA), In tabA i have a column (id) which is part of primary key
    Question: I need to know all the tables which have foreign keys refererring to tabA.id
    I used the following sql, please let me know if this is correct:
    select table_name
      from dba_constraints
    where (r_constraint_name) in ( select constraint_name
                                      from dba_constraints
                                     where table_name = 'tabA'
                                       and constraint_type in ( 'P', 'U' ) );

    On 11.2 you could try recursive subquery factoring:
    select *
    from ( with the_constraints( table_name
                               , constraint_name
                               , r_constraint_name
                               , lvl
           as ( select a.table_name
                ,      a.constraint_name
                ,      a.r_constraint_name
                ,      1 lvl
                from   all_constraints a
                where  a.table_name  = 'tabA'
                and    a.constraint_type = 'P'
                union all
                select c.table_name
                ,      nvl(( select constraint_name
                             from   all_constraints
                             where  table_name = c.table_name
                             and    constraint_type = 'P'
                          , c.constraint_name
                ,      c.r_constraint_name
                ,      lvl+1
                from   the_constraints p,
                       all_constraints c
                where  p.constraint_name = c.r_constraint_name
                and    c.constraint_type = 'R'
           search depth first by table_name set seq
           cycle table_name set is_cycle to 1 default 0
           select rownum rn
           ,      lpad('>', (lvl-1)*2, '-')||table_name relation
           ,      c.*
           from   the_constraints c
    order by rn desc;

  • How to find all child tables

    Hi,
    I have a set of tables that are in multi level hierarchy.
    Here is the example.
    Table1 (id is primary key)
    Table2 (id,loc is primary key. and id is refering to table1.id) Table3(id,name is primary key and id is refering to table1)
    Table 4(emp_id,group,name,loc_grp is PK. emp_id and loc_grp is refering to table2) Table5(std_id,name,dpt,sal is pk and std_id,name is refering to table3)
    Now, I want to get all tables and their columns that are refering to Table1.id. In this example, it should return table2, table3,table4 and table5 along with their columns.
    some thing like this.
    Table_name Column_name
    Table2 id
    Table3 id
    Table4 emp_id
    Table5 std_id
    Please suggest how to get this.

    HI ,please try this one .
    SELECT a.table_name, c.column_name, b.table_name AS child_table,
           d.column_name, b.r_constraint_name
      FROM user_constraints a,
           user_constraints b,
           user_ind_columns c,
           user_cons_columns d
    WHERE a.constraint_type = 'P'
       AND a.constraint_name = b.r_constraint_name
       AND b.constraint_type = 'R'
       AND a.table_name = c.table_name
       AND a.constraint_name = c.index_name
       AND b.constraint_name = d.constraint_name
       AND a.table_name = '<TABLE_NAME>' ;thanks,
    P Prakash

  • How to find all the tables associated for a particular transaction

    Hi-
    May I know how to find all the tables, related(foreign key) tables for a transaction within SAP GUI?
    Up to my technical knowledge, this can be achieved by looking database diagrams from DB level. But that would be for entire database as a whole. What I'm expecting is to see transaction level relative tables that too from SAP GUI. Please share the possibilities if any.
    Regards
    Sekhar

    Dear Micky Oestreich
    May be we possess expertise or high level experience, it should not show up in our way of communication. Every professional starts with the basic stuff to learn. When the question is raised in such minimum polite way, the same level of courtesy is expected in return. If you felt my question was basic, you might have refused it gently. If you are in good mood or bad mood it doesn't matters.
    Hi Vengal Rao
    Thanks for your response. It helped me.
    Regards
    Sekhar

  • How to find all the table used in a report

    Hi Expert ,
                    Is there is any program  to find out all the tables which  are used in a perticular report .
    Thanks in advance
    Tarak

    Well, so far Viquar Iqbal has given the only really correct answer - use SQL trace.  The reason the others are incomplete, is because they don't consider that a report might call a function module or a class method that accesses a table.  In fact, for many applications this is exactly what happens - db accesses are abstracted away from the main program.
    The other alternative to SQL trace is to use Run Time Analysis.  The advantage of SQL trace is that it shows the tables hit in order.
    matt

  • Need to delete data from main table and all child tables ...

    hi all,
    i need to delete rows pertaining to perticular table and all the child
    tables basing on certain code.i need to write a procedure to which i will
    pass the table name and code..
    like del_info(tab_name,code)
    example:
    suppose if i call as del_info(clients,760)
    the procedure should delete all info reg. code 760
    and the table clients and also all the child records of this table
    perting to code 760.
    simply .. i need to delete from the table passed and also
    all the child tables down the heirarchy regarding certain code ...
    help ???
    Ravi Kumar M

    Hi,
    Depends how you defined referential integrity.
    You can use ON DELETE CASCADE, please read the next doc http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/clauses3a.htm#1002692
    Hope this help you,
    Nicolas.

  • How to find All backup table in the d/b with different suffix?

    I need to find out all backup tables where table having suffix like BKUP and some dates in number.
    For e.g.:
    WX_ACCOUNT_YEAR_FUND_BKUP
    WX_ACTUALS_CATEGORY_D_APR05
    WX_ACTUALS_F_APR05
    WX_ACTUALS_F_BACKUP_APR05
    WX_ACTUALS_F_JAN_17_2006
    WX_ACTUALS_F_JUL05
    WX_CHECK_BOOK_HEADER_D_010306
    WX_DIMENSION_ACTUALS_OLD
    WX_DIMENSION_ACTUALS_OLD_APR05
    W_ORG_DSXBKP09292005
    Is there any way to find such tables by using SQL query.

    WITH T
    as
    select 'WX_ACCOUNT_YEAR_FUND_BKUP' table_name from dual
    union all
    select 'WX_ACTUALS_CATEGORY_D_APR05' from dual
    union all
    select 'WX_ACTUALS_F_APR05' from dual
    union all
    select 'WX_ACTUALS_F_BACKUP_APR05' from dual
    union all
    select 'WX_ACTUALS_F_JAN_17_2006' from dual
    union all
    select 'WX_ACTUALS_F_JUL05 ' from dual
    union all
    select 'WX_CHECK_BOOK_HEADER_D_010306' from dual
    union all
    select 'WX_DIMENSION_ACTUALS_OLD' from dual
    union all
    select 'WX_DIMENSION_ACTUALS_OLD_APR05' from dual
    union all
    select 'W_ORG_DSXBKP09292005' from dual
    union all
    select 'W_ORG_DSXBKP' from dual
    select table_name from t
    where regexp_like(table_name,'[[:digit:]]$')
    or ( table_name  like '%BKUP' or table_name  like '%OLD')I have considered the table names ending with OLD also as backup tables. If this is not a backup table then remove the condition from the where clause
    Regards,
    Mohana

  • How to find out child tables

    Hi,
    My data base Table master_accouts contain some of child tables. I would like to
    Know How can i findout How many tables/what r those tables. Please guide me.
    warm regards,
    Venkat.

    Hi,
    My data base Table master_accouts contain some of child tables. Could you please give more information on what you want ?
    If you want to find the constraints then yo can use ALL_CONS_COLUMNS view to get the constraints.
    Thanks

  • How find the child tables

    hi
    is there a way(quesry) to find the list of child tables for a given tables.
    tried to query user_constraints and USER_CONS_COLUMNS, but not able to figure out a way.
    Thanks

    Hi,
    you can use query like following one - it'll list child tables and FK name for table HR.JOBS:
    select
    a.owner,a.table_name, a.constraint_name
    from sys.all_constraints a,
    (select owner,constraint_name from sys.all_constraints where owner = *'HR'* and table_name = *'JOBS'* and constraint_type in ('P','U')) b
    where
    a.constraint_type = 'R' and a.r_constraint_name = b.constraint_name and a.r_owner = b.owner
    if you don't need FK name, then put distinct:
    select
    distinct a.owner,a.table_name
    from sys.all_constraints a,
    (select owner,constraint_name from sys.all_constraints where owner = 'HR' and table_name = 'JOBS' and constraint_type in ('P','U')) b
    where
    a.constraint_type = 'R' and a.r_constraint_name = b.constraint_name and a.r_owner = b.owner
    Philip

  • How to find  out child tables given a parent table /parent's constraint_nam

    Hi
    I need to disable a primary key but is not able to becoz of referential constraint
    select child_constraint.table_name, child_constraint.constraint_name, child_detail.column_name
    from user_cons_columns child_detail
    join user_constraints child_constraint
    on child_detail.constraint_name = child_detail.constraint_name
    and child_detail.owner = child_detail.owner
    and child_detail.table_name= child_detail.table_name
    where child_constraint.constraint_type='R'
    and child_constraint.status='ENABLED'
    and child_constraint.r_constraint_name='SUBSCRIBER_PK';
    and child_detail.table_name='ADDRESS_BOOK_GROUP';
    Given a table name how would I know all the child tables and the child tables' columns referencing the parent keys?
    thanks

    thanks for the reply
    while the first query is correct
    select child_constraints.table_name child_table_name, child_detail.constraint_name child_constraint_name
    , child_detail.column_name child_column_name, child_constraints.constraint_type child_constraint_type
    , child_constraints.status, parent_constraints.table_name parent_table_name, parent_detail.column_name parent_column_name
    , parent_constraints.constraint_name parent_constraint_name
    , parent_constraints.status parent_constraint_status from
    user_cons_columns child_detail
    join user_constraints child_constraints
    on child_detail.constraint_name=child_constraints.constraint_name
    and child_detail.owner=child_constraints.owner
    and child_detail.table_name=child_constraints.table_name
    join user_constraints parent_constraints
    on parent_constraints.constraint_name=child_constraints.r_constraint_name
    join user_cons_columns parent_detail
    on parent_detail.constraint_name=parent_constraints.constraint_name
    and parent_detail.owner=parent_constraints.owner
    and parent_detail.table_name=parent_constraints.table_name
    where
    child_constraints.r_constraint_name in (
    select constraint_name from user_constraints parent_constraint
    where parent_constraint.constraint_type='P'
    and parent_constraint.status='ENABLED'
    and parent_constraint.table_name='SUBSCRIBER'
    and child_constraints.constraint_type='R'
    and parent_constraints.constraint_type='P'
    --and child_constraints.status='ENABLED'
    order by child_constraints.table_name
    , child_detail.position
    the second query return a lots of garbage why is this so?
    select child_constraints.table_name child_table_name, child_detail.constraint_name child_constraint_name
    , child_detail.column_name child_column_name, child_constraints.constraint_type child_constraint_type
    , child_constraints.status, parent_constraints.table_name parent_table_name, parent_detail.column_name parent_column_name
    , parent_constraints.constraint_name parent_constraint_name
    , parent_constraints.status parent_constraint_status from
    user_cons_columns child_detail
    join user_constraints child_constraints
    on child_detail.constraint_name=child_constraints.constraint_name
    and child_detail.owner=child_constraints.owner
    and child_detail.table_name=child_constraints.table_name
    join user_constraints parent_constraints
    on parent_constraints.constraint_name=child_constraints.r_constraint_name
    join user_cons_columns parent_detail
    on parent_detail.constraint_name=parent_constraints.constraint_name
    and parent_detail.owner=parent_constraints.owner
    and parent_detail.table_name=parent_constraints.table_name
    where
    child_constraints.constraint_type='R'
    and parent_constraints.constraint_type='P'
    --and child_constraints.status='ENABLED'
    order by child_constraints.table_name
    , child_detail.position
    thanks

  • Query to Find all the Tables and their corresponding columns,dataType in DB

    Hi all,
    I need a query which can give me all the Tables existing in my DB and their corresponding Columns existed for those tables and Datatype for each column .
    Thanks in Advance,
    viajy

    Hi,
    For your user tables you can use USER_TAB_COLUMNS.
    Just give DESC USER_TAB_COLUMNS at your SQL> prompt.
    You will know on that object.
    Regards,
    Sailaja

  • How to find all Custom tables (transp) that have a custom transaction code?

    My client has asked us to provide a list of all Z (custom) tables and the associated transaction codes for maintaining them.
    I know I can manually do this with a Z* search in se11 and then do a where used on each table to find out if a view (transaction code) exists for the table - BUT THIS WOULD TAKE HOURS IF NOT DAYS TO DO AND BE LIABLE FOR HUMAN ERROR.
    Does anyone know the way we could code a search for this information (ABAP) and know what tables to use?
    Thanks.
    Scott

    Hi
    You can search in table TSTCP for custom tables that have a maintainance view and a transaction associated, which is a call to SM30. To do this, just select the table with TCODE starting with 'Z' and PARAM starting with '/*SM30'.
    But you can also have some Z tables updated by an module pool program. This is more complex to find, because you don't know if you simply have the field used in the screen for some other use in a transaction, or if it is in that screen just to update the table. In this case, you need to analyze each screen.But I hope the first tip help you to solve your problem.

  • How to find all the tables by feild value in oracle

    Hi ...
    I have a requirement to find the tables in a particular schema(suppose DEMO) by Field value..
    Ex:
    suppose in a  schema called DEMO  i have the tables.......T1,T2,T3,T4,T5..
    all the above tables have the name column..
    now i wan to know the tables whose column(name) have value as rajani.......
    pls help.........
    thank you
    .+

    Solutions from previous requests for the same...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

  • FIND ALL CHILD DEPARTMENTS

    Dear All,
    i have a table
    create table dept(dept_id number primary key,
    dept_name varchar2(100),
    reference_dept number references dept(dept_id);
    THERE is a main Department with dept_id=1
    there are child of the 1 which are 2,3,4
    if i choose the dept_id =4 then i want to select all the dept_id upto the parent dept_id i.e up to 1
    and
    if i choose the dept_id=1 then i want to select all the dept_id down the last chile dept_id i.e up to 4
    how to do this?
    thanks & Regards

    For "journey" down by the tree you can use
    select * from dept
    start with dept_id = 1
    connect by prior dept_id = reference_deptand for "journey" from bottom to the top of the three you can use
    select * from dept
    start with dept_id = 4
    connect by dept_id = prior reference_dept

Maybe you are looking for

  • Adding a new field in Oracle Selfservice /Internet Time

    Dear All I need to add a column in detail frame of the Self Service Time - Create Time card page. In Master level we have employee name, Manager name, weekending date, General Comments. In detail level we have Project number, Task Number,Type,mon,tue

  • Import messages from thuinderbird to Mail

    I am trying to import my messages from thunderbird 3.1 to _Mail 4.4._ The import procedure suggested from Mail app doesn't work correctly because it leaves several messages without importing them. I even tried to rename thunderbird's mailboxes to .mb

  • How to make cost element field appear when create network activity service

    Hi All, Please help. We create a project ,wbs and network activity using external service. How can we make appear the cost element when the service master appear. The system require cost element but we cannot see the cost element field. Steps : *. CJ

  • Photoshop Elements 9 prints and Previews are blank

    Recently installed Elements (not the trial, the paid version) on a new MacBook Pro, and it not only won't print, the Print Preview is blank. Wondering if it was the document, so I created a new document with Elements, painted a few strokes, and tried

  • Jumpstarting / tftp download fails

    Hi, I setup a Solaris 10 x86 /1106 jumpstart server. I was able to install a Dell Latitude D420 using this jumpstart server. However if I try to install another x86 machine the booting process hangs after fetching the correct IP from the DHCP server.