MySql 中的自动视图更新

发布于 2024-12-14 15:19:36 字数 90 浏览 3 评论 0原文

当 MySQL 中的基础表更新时,视图是否会自动更新而无需查询?

进一步详细说明 - 如果我更新表,那么即使我不在视图上运行任何查询,视图也会更新吗?

Does the view get automatically updated when the underlying tables get updated in MySQL without querying?

To further elaborate - if I update the table then does the view get updated even if I don't run any query on the view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

-小熊_ 2024-12-21 15:19:36

每次在视图上执行查询时,它将获取表中当前的数据 - 包括其上所有已提交的事务,但不包括那些尚未提交的 UPDATE 或 INSERT 查询。

但当然,一旦您获得了该数据,它就不会再次发送。有触发器,但您的数据库客户端仍然必须查询视图数据。

澄清一点:视图不存储(缓存)数据,它是一个逻辑结构,并且始终会查看基础表。

Every time you execute a query on the view, it will fetch the data currently in tables - included all committed transactions on it, but not those UPDATE or INSERT queries taht have still not been committed.

but of course, once you have got that data, it will not send it again. There are triggers for that, but still your database client has to query the view data out.

To clear up a bit more: View does not store (cache) the data, it is a logical structure and will always look into the underlying tables.

一场信仰旅途 2024-12-21 15:19:36

视图是可作为虚拟表访问的存储查询,由查询的结果集组成。
更改引用表中的数据会更改视图的后续调用中显示的数据。

请参阅:http://en.wikipedia.org/wiki/View_(database)

有点像这样......

如果你现在问我时间我会告诉你现在是十点。

如果 2 小时后你问我,我会告诉你现在是十二点。

除非你问我,否则我不会一直告诉你时间。

A view is a stored query accessible as a virtual table and is composed of the result set of the query.
Changing the data in a referenced tables alters the data shown in subsequent invocations of the view.

see: http://en.wikipedia.org/wiki/View_(database)

its a bit like this.....

If you ask me the time now I will tell you it is ten o'clock.

If you ask me 2 hours later I will tell you it is twelve o'clock.

Unless you ask me I will not keep telling you the time.

记忆之渊 2024-12-21 15:19:36

如果您创建了某个表的视图,那么当您更改数据或在其各自的表中插入新数据时,视图中的数据会自动更新。

但是,如果您想在数据库表中添加更多列并更新其各自的视图,则更改不会自动进行。

为此,您可以使用“SQLYog”。这是处理视图的好工具。

If you have created the view of certain table then there is automatic update in the data in the view as you change the data or insert new data in its respective table.

However if you want to add more columns in the database table and update its respective view then the change is not automatic.

For that you can use 'SQLYog'. It is nice tool to work with views.

橘虞初梦 2024-12-21 15:19:36

通常VIEWS会自动更新。

来自 MySQL 文档

某些视图是可更新的。也就是说,您可以在诸如此类的语句中使用它们
作为 UPDATE、DELETE 或 INSERT 来更新底层内容
桌子。为了使视图可更新,必须有一个一对一的
视图中的行与视图中的行之间的关系
底层表。还有某些其他结构可以使
查看不可更新。

generally VIEWS updated automatically.

From MySQL Documentation

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 nonupdatable.

白日梦 2024-12-21 15:19:36

是的,MySQL 中的视图会自动更新;包括但不限于:

  • 更改表结构
  • 在表上插入/更新/删除过程
  • 使用 CREATE 或 REPLACE VIEW 更改视图结构

注意:更改表的结构需要重新创建视图。

Yes, Views automatically update in MySQL; including, but not limited to:

  • Changing table structures
  • Insert/Update/Delete procedures on Tables
  • Changing View structures using CREATE OR REPLACE VIEW

NOTE: Changing a table's structure requires re-creating the View.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文