简体   繁体   English

“ SHOW COLUMNS”命令中的字段如何映射到特定表?

[英]How do the fields in “SHOW COLUMNS” command map to specific tables?

Here is a View called viewwithcommonfield : 这是一个名为viewwithcommonfield的视图:

SELECT 
        `schematopologytest01`.`talpha`.`CommonField` AS `CommonField_tAlpha`,
        `schematopologytest01`.`tbeta`.`CommonField` AS `CommonField_tBeta`
    FROM
        (`schematopologytest01`.`talpha`
        JOIN `schematopologytest01`.`tbeta`)

When I execute 当我执行

SHOW FULL fields FROM viewwithcommonfield IN SchemaTopologyTest01

I get this: 我得到这个: SHOW FULL ...的结果

How do I map the fields back to specific tables? 如何将字段映射回特定表? Can I write a view against the tables in information_schema? 我可以针对information_schema中的表编写视图吗?

Here are the table structures that are referenced in the view. 这是视图中引用的表结构。 The tables share a common field called CommonField : 这些表共享一个称为CommonField的公共字段: 在此处输入图片说明

No, there is no metadata available to map views of a column back to the original column in a base table. 不,没有元数据可用于将列视图映射回基表中的原始列。 That would require multiple tables, because any given expression in the select-list may reference multiple columns from different tables. 这将需要多个表,因为选择列表中的任何给定表达式都可以引用来自不同表的多个列。

Consider: 考虑:

SELECT CONCAT(
  `schematopologytest01`.`talpha`.`AlphaFieldA`,
  `schematopologytest01`.`tbeta`.`BetaFieldE`) AS `ConcatenatedField`
FROM `schematopologytest01`.`talpha`
JOIN `schematopologytest01`.`tbeta` ON ...

Which table and column would ConcatenatedField list as its origin? ConcatenatedField会将哪个表和列列为源? It would have to be stored in two rows of another INFORMATION_SCHEMA table. 它必须存储在另一个INFORMATION_SCHEMA表的两行中。

There are also select-list expressions possible in a view that don't reference any base table: 视图中还有不引用任何基表的选择列表表达式:

CREATE VIEW ViewNow AS SELECT NOW() AS `now`;

What about columns that are themselves scalar subqueries? 那么本身就是标量子查询的列呢? Or references to stored functions? 还是对存储函数的引用? Or an aggregate function like COUNT() or SUM() where the value is not found in any base table? 还是像COUNT()SUM()这样的聚合函数,在任何基本表中都找不到该值?

Many views do not derive their data from base tables deterministically at all. 许多视图根本没有确定性地从基表中获取数据。 Edit: What I mean is that it's not always possible to know which rows or columns are the source of data in a view, because they results are combined in some ways. 编辑:我的意思是,并非总是可能知道视图中的数据源是哪些行或列,因为它们的结果以某种方式组合在一起。 It's probably more clear to say that reversing the query to get the original data is not always possible, depending on the query. 可能更清楚地说,取决于查询,并非总是可以反向查询以获取原始数据。

It's not possible to update those views. 无法更新这些视图。 But if there were metadata about where the data "came from," there would have to be something in the metadata to indicate that. 但是,如果存在有关数据“来自何处”的元数据,则元数据中必须有一些内容来表明这一点。 It would be impractical because it would be complex, and have little value. 这将是不切实际的,因为它很复杂,而且价值不大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM