0
A
回答
2
如果您使用的是MySQL 5.1或更高版本,則可以使用REFERENTIAL_CONSTRAINTS
table from information schema。喜歡的東西:
select references_table_name
from referential_constraints
where table_name = 'your_table';
0
select referenced_table_name, referenced_column_name
from information_schema.key_column_usage
where table_name = 'Yourtable' and column_name='id'
1
SELECT CONSTRAINT_NAME, ORDINAL_POSITION, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE
TABLE_NAME = 'table_name' AND
TABLE_SCHEMA = 'database_name' AND
REFERENCED_TABLE_SCHEMA = 'database_name';
ORDINAL_POSITION
可能會感興趣的,當你有組合鍵。
可能重複[MySQL:如何確定外鍵關係編程?](http://stackoverflow.com/questions/273794/mysql-how-to-determine-foreign-key-relationships-programmatically)。我不建議使用動態外鍵關係 - 正確模擬情況。 – 2010-09-15 19:08:05