MySQL: How do I find out which tables reference a specific table?

前端 未结 7 1975
挽巷
挽巷 2021-01-31 08:21

I want to drop a table but it is referenced by one or more other tables. How can I find out which tables are referencing this table without having to look at each of the tables

相关标签:
7条回答
  • 2021-01-31 08:44
    select table_name
    from information_schema.KEY_COLUMN_USAGE
    where table_schema = 'my_database'
    and referenced_table_name = 'my_table_here';
    

    This works.

    0 讨论(0)
  • 2021-01-31 08:44

    you could try MySql workbench which allows you to extract E.R. diagram. In this you can find all you need about tables of your database.

    0 讨论(0)
  • 2021-01-31 08:47

    Use Toad to load it up and you can view the references through the diagram. also make sure that you don't have any app code passing sql from the front-end, dropping the table may cause the app to break.

    Download link http://www.toadsoft.com/toadmysql/FreewareDownload.htm

    If you are using innoDB try this one SHOW TABLE STATUS FROM yourdatabasename LIKE 'T' http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html

    0 讨论(0)
  • 2021-01-31 08:50

    from the mysql command line: show table status

    0 讨论(0)
  • 2021-01-31 08:53

    If you have phpMyAdmin installed, you can use its designer feature to visualize table relationships.

    To use the designer, select a database, then look for the Designer tab.

    0 讨论(0)
  • 2021-01-31 09:07
    select table_name 
    from information_schema.referential_constraints 
    where referenced_table_name = 'parent table here';
    
    0 讨论(0)
提交回复
热议问题