Mysql
 sql >> Database >  >> RDS >> Mysql

Mysql mostra creare vincoli?

Per mostrare solo i vincoli di chiave esterna puoi controllare il constraint_type in information_schema.table_constraints e ottenere le colonne interessate in information_schema.key_column_usage tramite un join

SELECT b.table_name, b.column_name, b.constraint_name,
       b.referenced_table_name, b.referenced_column_name
FROM information_schema.table_constraints a
JOIN information_schema.key_column_usage b
ON a.table_schema = b.table_schema AND a.constraint_name = b.constraint_name
WHERE a.table_schema=database() AND a.constraint_type='FOREIGN KEY'
ORDER BY b.table_name, b.constraint_name;