यह समाधान न केवल सभी संबंधों को प्रदर्शित करेगा, बल्कि बाधा नाम भी होगा, जो कुछ मामलों में आवश्यक है (उदा। ड्रॉप अवरोध):
select
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references',
constraint_name as 'constraint name'
from
information_schema.key_column_usage
where
referenced_table_name is not null;
यदि आप किसी विशिष्ट डेटाबेस में टेबल को जांचना चाहते हैं, तो क्वेरी के अंत में तालिका का नाम जोड़ें:
select
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references',
constraint_name as 'constraint name'
from
information_schema.key_column_usage
where
referenced_table_name is not null
and table_schema = 'database_name';
इसी तरह, एक विशिष्ट कॉलम नाम के लिए, जोड़ें
और table_name = 'table_name
प्रश्न के अंत में।
Inspired by this post here