1

How to find tables all relation in MySQL. whether it references some table, or some other table will take its reference.

For example, suppose student is a table which contains id (primary key), name, class(Foreign key refers class table id field) element. And class is an another table which contains id(primary key), name. and another table student_account is an another table which contains id(primary key), student_id(Foreign key refers student table id field),due.

Now how may I find all relation of table student.

1 Answers1

1

You can try this.

 SELECT TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
 FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = Your_Table_Name
 AND REFERENCED_TABLE_SCHEMA IS NOT NULL AND REFERENCED_COLUMN_NAME IS NOT NULL AND
 REFERENCED_TABLE_NAME IS NOT NULL
Shashank Singh
  • 1,280
  • 12
  • 23