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