SELECT
TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME,
REFERENCED_TABLE_NAME,
REFERENCED_COLUMN_NAME
FROM
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
REFERENCED_TABLE_SCHEMA = 'db_name'
AND REFERENCED_TABLE_NAME = 'table_name';
mysql> SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME
> FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
> WHERE REFERENCED_TABLE_SCHEMA IS NOT NULL;
+--------------+---------------+-------------+-----------------+
| TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME |
+--------------+---------------+-------------+-----------------+
| fk1 | myuser | myuser_id | f |
| fk1 | product_order | customer_id | f2 |
| fk1 | product_order | product_id | f1 |
+--------------+---------------+-------------+-----------------+
3 rows in set (0.01 sec)
Code Example |
---|
Sql :: foreign key on table oracle |
Sql :: mysql default uuid |
Sql :: mariadb create view |
Sql :: sql server datetime |
Sql :: oracle undo tablespace schema |
Sql :: psql shell |
Sql :: mysql group by |
Sql :: cast in sql |
Sql :: order by sql query |
Sql :: copy table in sql |
Sql :: union postgresql |
Sql :: case condition in mongodb |
Sql :: sql server datetime vs datetime2 |
Sql :: creating sql table |
Sql :: select only unique values from and to current table |
Sql :: mysql count |
Sql :: how to delete last row in sql |
Sql :: postgresql having |
Sql :: sql use with to get value counts and percentages |
Sql :: mysql workbench |
Sql :: how to check common records in 2 table |
Sql :: windows aggregate functions in postgresql |
Sql :: tsql generate rows |
Sql :: postgresql get difference in hours between two dates |
Sql :: alter database datafile maxsize 32g |
Sql :: index postgres |
Sql :: sql join on wildcard |
Sql :: how to get last element sql |
Sql :: cross join sl |
Sql :: oracle no data found error code |