P粉3279030452023-08-23 13:34:50
Use information_schema.table_constraints
table to get the name of the constraints defined on each table:
select * from information_schema.table_constraints where constraint_schema = 'YOUR_DB'
Use information_schema.key_column_usage
table to obtain the fields in these constraints:
select * from information_schema.key_column_usage where constraint_schema = 'YOUR_DB'
If you want to discuss foreign key constraints, use information_schema.referential_constraints
:
select * from information_schema.referential_constraints where constraint_schema = 'YOUR_DB'