我有一个由两个表组成的视图表(让我们称之为view_table
)(让我们称之为table_1
& table_2
)。我们假设table_1
在引用表fk_field
的字段fk_table
上有一个外键。
是否有直接查询view_table
以获取字段fk_table
的参考表fk_field
?
我是用PHP做的,所以我想做的事情就是:
VIEW_DEFINITION
解析INFORMATION_SCHEMA.VIEWS
字段,以获取构成view_table
的表格列表(例如table_1
& table_2
)fk_table
是否有更好(即更简单)的方法?
修改
在这种情况下的视图定义,字段Container
是一个引用名为Containers
的表的外键:
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `LIMS_dev`.`DerivativeView` AS
SELECT
`a`.`Derivative` AS `Derivative`,
`a`.`Container` AS `Container`,
`a`.`DerivativeTypeID` AS `DerivativeTypeID`,
`a`.`StorageFormatID` AS `StorageFormatID`,
`a`.`SourceSample` AS `SourceSample`,
`a`.`Parent` AS `Parent`,
`a`.`Date` AS `DerivativeDate`,
`a`.`Active` AS `SampleActive`,
`a`.`User` AS `User`,
`a`.`Notes` AS `Notes`,
`b`.`Shelf` AS `Shelf`,
`b`.`Rack` AS `Rack`,
`b`.`FreezerID` AS `FreezerID`,
`b`.`Active` AS `BoxActive`,
`b`.`Date` AS `ContainerDate`
FROM
(`LIMS_dev`.`Derivatives` `a`
LEFT JOIN `LIMS_dev`.`Containers` `b` ON ((`a`.`Container` = `b`.`Container`)))