Need T-SQL to list tables by Parent, Dependent, Descendent, etc

  • Looking for T-SQLto list my tables in a single database in hierarchical fashion.. with all PARENT tables 1st, followed by all dependants, then all descendants, etc..

    eg.

    Corporation_Table

    Branch_Table

    Division_Table

    Department_Table

    Employee_Table

    thx in advance

    BT
  • Hi,

    if you know one parent table you can get all dependencies with the attached script (captured from sql server profiler). (the parent table is in line 15)

    Maybe it helps as a starting point.

  • DBASkippack (4/6/2009)


    Looking for T-SQLto list my tables in a single database in hierarchical fashion.. with all PARENT tables 1st, followed by all dependants, then all descendants, etc..

    eg.

    Corporation_Table

    Branch_Table

    Division_Table

    Department_Table

    Employee_Table

    thx in advance

    Probably a silly question but have to make sure... Do you have DRI setup across all of these table that identifies the parent/child relationships?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Thanks for the quick feedback folks. and Yes, we have DRI implemented. (and for those tables without DRI, that's fine) --

    I'm just trying to identify the LOAD SEQUENCE for 100+ tables in my SSIS package.. My HARNESS package will fire sub-LOADERS which each contain individual SSIS pkg's ... Need to load those PARENTS 1st of course..

    BT

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply