查看整个 MySQL 数据库的所有外键约束

2022-01-20 00:00:00 database foreign-keys mysql

我有一个包含 150 多个表的大型数据库,我最近收到了这些表.我只是想知道是否有一种简单的方法可以查看整个数据库的所有外键约束,而不是基于每个表.

I have a large database with over 150 tables that I've recently been handed. I'm just wondering if there is an easy way to view all foreign key constraints for the entire DB instead of on a per-table basis.

推荐答案

你可以使用INFORMATION_SCHEMA 表.例如,INFORMATION_SCHEMA TABLE_CONSTRAINTS 表.

You can use the INFORMATION_SCHEMA tables for this. For example, the INFORMATION_SCHEMA TABLE_CONSTRAINTS table.

应该这样做:

select *
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_TYPE = 'FOREIGN KEY'

相关文章