How to find all the relations between all mysql tables?

前端 未结 9 1954
甜味超标
甜味超标 2020-12-01 01:12

How to find all the relations between all MySQL tables? If for example, I want to know the relation of tables in a database of having around 100 tables.

Is there any

9条回答
  •  情话喂你
    2020-12-01 01:26

    1) Go into your database:
    use DATABASE;

    2) Show all the tables:
    show tables;

    3) Look at each column of the table to gather what it does and what it's made of:
    describe TABLENAME;

    4) Describe is nice since you can figure out exactly what your table columns do, but if you would like an even closer look at the data itself: select * from TABLENAME
    If you have big tables, then each row usually has an id, in which case I like to do this to just get a few lines of data and not have the terminal overwhelmed:
    select * from TABLENAME where id<5 - You can put any condition here you like.

    This method give you more information than just doing select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS;, and it also provides you with more bite-sized information each time.

    EDIT

    As the comments suggested, the above WHERE id < 5 was a bad choice as a conditional placeholder. It is not a good idea to limit by ID number, especially since the id is usually not trustworthy to be sequential. Add LIMIT 5 at the end of the query instead.

提交回复
热议问题