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

标签 mysql

我试试这个:

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/

相关文章:

javascript - 最后在 tbody 的每个表行中插入额外的列

php - MYSQL Join 语句 - 在列表中

php - 在结果数组中添加参数

php - mysql查询: retrieve current date query

php - 循环检查并删除图像(如果不存在)

mysql - 将数据从本地计算机上的 dbf 文件持续导入 MySQL 的最简单方法

mysql - 如何使用MySQL找出多个组中一列的计数?

MySQL如何将值舍入到ceil

mysql - 大小写语法错误

c++ - 用mysql原生函数进行字节序转换