In a MYSQL database I want to find out all the tables in the current db that have my selected table's primary key as their foreign key, in other words they are referring to my table.
Asked
Active
Viewed 753 times
0
-
Already asked and answered here: https://stackoverflow.com/questions/201621/how-do-i-see-all-foreign-keys-to-a-table-or-column – Piemol Oct 04 '18 at 18:07
2 Answers
1
You can just do something like this:
USE information_schema;
SELECT *
FROM
key_column_usage
WHERE
REFERENCED_TABLE_NAME = 'table_name'
AND REFERENCED_COLUMN_NAME = 'table_id'
AND TABLE_SCHEMA = 'your_database_name';
Replace the table_name
and table_id
with the your table name and column name.

Pritam Banerjee
- 17,953
- 10
- 93
- 108
-
It gives me a error code 1064, there is something wrong with my sql syntax – anwesh mohapatra Oct 04 '18 at 18:14
1
I guess the last answer was almost correct. just change the table from "key_column" to "key_column_usage.
Cheers
Nikao

nicolasl
- 421
- 3
- 16