doushang3352 2013-07-17 08:53
浏览 518

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

I have table _house with field 'soft_delete' default is 0.

Then I have a View to check undeleted entries, hence I have

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

But the problem now is that everytime I modify table _house, I'll need to re-update my view so that is not broken.
So each time after modify table _house, I execute

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

I wanted to find an easier way to execute above alter script, so I tried to create a procedure/function with 'alter view' inside, but mysql seems to prohibit me doing that.

Question :

  • Any other solution to simplify this 'redundant' actions ?
  • 写回答

1条回答 默认 最新

  • dongpu9481 2013-07-17 08:57
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥20 Keil编译时报错"no source": Error: #5: cannot open source
  • ¥50 操作系统时间无法更新
  • ¥20 Windows11, usb转hdmi,外接显示器无反应
  • ¥20 怎么在JavaFx的TableView中动态地添加数据。
  • ¥15 MFC里的工具栏按钮图标使用外部图片
  • ¥15 如何在 llama.cpp 服务器中实现用户登录功能的优化方案?(语言-c++)
  • ¥15 有会用octave 的吗,急!代做!好偿!
  • ¥15 有一套同城小程序源码,Uniapp前端,php+html+mysql后端 ,能不能教我搭建起来可以运行,我不知道怎样操作
  • ¥15 mac调用java.io接口无法在根目录生成文件
  • ¥15 java微服务节点假死,网关路由时长延迟