I'm trying to figure out the foreign keys relationship within my MySQL databases.
I have many tables that has the "mydomain_id" column located in other tables.
Is there a command line I can use to list all tables that has that particular column?
I'm trying to figure out the foreign keys relationship within my MySQL databases.
I have many tables that has the "mydomain_id" column located in other tables.
Is there a command line I can use to list all tables that has that particular column?
SELECT
DISTINCT `table_name`
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
COLUMN_NAME IN ('name') AND
TABLE_SCHEMA='symfony_backend';
Gives: (all the tables listed below exist in my database symfony_backend
)
table_name
'child'
'country'
'league'
'parent'
'player'
'schools'
'student'
'team'
'user'
You can feed more column names with: COLUMN_NAME IN ('name', 'another_column', 'and_another_one')
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'db_name'
AND column_name = 'mydomain_id'