相关表结构发生变化时,mysql会自动更新视图吗?

时间:2013-07-17 08:53:08

标签: php mysql view

我有table _house,字段'soft_delete'默认为0.

然后我有一个View来检查未删除的条目,因此我有

CREATE VIEW house AS 
SELECT * FROM _house where soft_delete = 0;

但现在的问题是,每当我修改table _house时,我都需要重新更新我的视图,这样就不会破坏。
所以每次修改table _house后,我执行

ALTER VIEW house AS 
SELECT * FROM _house where soft_delete = 0;

我想找到一种更简单的方法来执行上面的alter script,所以我尝试用'alter view'创建一个过程/函数,但mysql似乎禁止我这样做。

问题:

  • 任何其他简化此“冗余”行动的解决方案?

1 个答案:

答案 0 :(得分:0)

The view definition is “frozen” at creation time, so changes to the underlying tables afterward do not affect the view definition. For example, if a view is defined as SELECT * on a table, new columns added to the table later do not become part of the view.

SOURCE