我需要编写一个php
脚本来处理MySql
数据库中的表。我知道表名,我需要在这个子表中通过名称外部字段知道名称父表。如何使用SQL
查询来完成?
更新
SELECT referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE table_name = '[child_table_name]'
AND column_name = '[foreign_key_field_name]'
答案 0 :(得分:2)
select referenced_table_name
from information_schema.REFERENTIAL_CONSTRAINTS
where table_name ='[child_table_name]'
--and constraint_name ='[foreign_key_constraint_name]'
更新
select referenced_table_name,
referenced_column_name
from information_schema.key_column_usage where table_name ='[child_table_name]'
and column_name='[foreign_key_constraint_name]';