Finding all related tables to a given table

前端 未结 4 1450
花落未央
花落未央 2021-02-02 08:36

I\'m working on a development with over 700 tables. I need to see a listing of all related tables to a given table. Can you recommend an app that is able to provide such a thing

4条回答
  •  春和景丽
    2021-02-02 09:00

    Depending on the database product, you should be able to query the INFORMATION_SCHEMA views like so:

    Select FK.TABLE_SCHEMA, FK.TABLE_NAME
    From INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS As RC
        Join INFORMATION_SCHEMA.TABLE_CONSTRAINTS As PK
            On PK.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME
        Join INFORMATION_SCHEMA.TABLE_CONSTRAINTS As FK
            On FK.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
    Where PK.TABLE_SCHEMA = 'dbo'
        And PK.TABLE_NAME = ''   
    

提交回复
热议问题