gpt4 book ai didi

mysql - 无法在 Mysql 中创建可更新 View

转载 作者:行者123 更新时间:2023-11-29 22:04:41 25 4
gpt4 key购买 nike

我试试这个:

CREATE VIEW ALL_urls AS 

SELECT * FROM TABLE1_urls
UNION ALL
SELECT * FROM TABLE2_urls
UNION ALL
SELECT * FROM TABLE3_urls
UNION ALL
SELECT * FROM TABLE4_urls

但是当我搜索“information_schema”时,我得到了这个:

IS_UPDATABLE
NO

知道如何使其“可更新”吗?

最佳答案

Some views are updatable. That is, you can use them in statements such as UPDATE, DELETE, or INSERT to update the contents of the underlying table. For a view to be updatable, there must be a one-to-one relationship between the rows in the view and the rows in the underlying table. There are also certain other constructs that make a view Non-Updatable.

更具体地说,如果 View 包含以下任何内容,则该 View 不可更新:

  • 聚合函数(SUM()、MIN()、MAX()、COUNT() 等)
  • DISTINCT GROUP BY HAVING UNION 或 UNION ALL 选择中的子查询
  • 列出某些连接
  • FROM 子句中的不可更新 View
  • WHERE 中的子查询
  • 引用 FROM 子句中的表的子句
  • 仅指文字值(在本例中,没有要更新的基础表)
  • 使用 ALGORITHM = TEMPTABLE(使用临时表始终会使 View 不可更新)- 对基表的任何列的多次引用。

有时多 TableView 是可以更新的,

Assuming that it can be processed with the MERGE algorithm. For this to work, the view must use an inner join (not an outer join or a UNION). Also, only a single table in the view definition can be updated, so the SET clause must name only columns from one of the tables in the view. Views that use UNION ALL are not permitted even though they might be theoretically updatable, because the implementation uses temporary tables to process them.

关于mysql - 无法在 Mysql 中创建可更新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32271399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com