SQL 中视图和物化视图的区别
任何数据库的主要组成部分是其表格,在为了使数据可访问性定制化的情况下,有视图的概念。换句话说,通过表格的视图,我们可以限制任何用户只能访问他应该访问的数据。现在基于视图的特点和特性,我们可以区分视图和物化视图。
In this article, we will discuss the important differences between Views and Materialized Views in SQL. But before, let’s have look into the basics of views and materialized view individually for better understanding of the differences between them.
Views in SQL
Views are the logical and virtual copy of a table that is created by executing a ‘select query’ statement. The views are not stored anywhere on the disk. Thus, every time, a query has to be executed when certain data is required. But, the query expression is stored on the disk.
视图没有与之相关的存储/更新成本。视图是根据特定的架构设计的,这意味着有一个SQL标准来定义视图。视图在数据需要被不经常访问,但数据经常更新时使用。
Materialized Views in SQL
Materialized views are the views whose contents are computed and stored. Materialized views are also a logical virtual table, but in this case the result of the query is stored in the table or the disk. The performance of the materialized views is better than normal views. This is because the data is stored on the disk.
有时,物化视图也被称为“索引视图”,因为查询后创建的表被索引,可以更快、更高效地访问。当数据需要频繁访问且表中的数据不经常更新时,会使用物化视图。
Difference between Views and Materialized Views in SQL
The following table highlights the important differences between Views and Materialized Views −
Key | Views | Materialized Views |
---|---|---|
Definition | 从技术上讲,表的视图是通过“select查询”创建的表的逻辑虚拟副本,但结果不会存储在磁盘上。 Whenever we need the data, we need to fire the query. So, the user always gets the updated or latest data from the original tables. |
Materialized views(物化视图)也是数据的逻辑虚拟副本,由“select查询”驱动,但查询结果将存储在表格或磁盘中。 |
Storage | In Views the resulting tuples of the query expression is not get storing on the disk only the query expression is stored on the disk. | 在物化视图的情况下,查询表达式和查询结果的元组都存储在磁盘上。 |
查询执行 | 查询表达式存储在磁盘上,而不是其结果,因此每次用户尝试从中提取数据时,查询表达式都会被执行,以便用户每次都能获得最新的更新值。 | The result of the query gets stored on the disk and hence the query expression does not get executed every time when user try to fetch the data so that user will not get the latest updated value if it get changed in database. |
成本效益 | 由于Views没有与之相关的存储成本,因此它们也没有与之相关的更新成本。 | Materialized Views有与之相关的存储成本,因此也有与之相关的更新成本。 |
Design | Views in SQL are designed with a fixed architecture approach due to which there is an SQL standard of defining a view. | Materialized Views in SQL are designed with a generic architecture approach, so there is no SQL standard for defining it, and its functionality is provided by some databases systems as an extension. |
使用情况 | Views are generally used when data is to be accessed infrequently and data in table get updated on frequent basis. | 当数据需要频繁访问且表中的数据不经常更新时,使用Materialized Views。 |
结论
在SQL中,视图(Views)和物化视图(Materialized Views)是非常不同的。当数据很少被访问,而表中的数据经常更新时,使用视图。相反,当数据需要频繁访问,而表中的数据不经常更新时,使用物化视图。
以上是SQL 中视图和物化视图的区别的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

本文讨论了使用MySQL的Alter Table语句修改表,包括添加/删除列,重命名表/列以及更改列数据类型。

文章讨论了为MySQL配置SSL/TLS加密,包括证书生成和验证。主要问题是使用自签名证书的安全含义。[角色计数:159]

文章讨论了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比较了它们对初学者和高级用户的功能和适合性。[159个字符]

本文讨论了使用Drop Table语句在MySQL中放下表,并强调了预防措施和风险。它强调,没有备份,该动作是不可逆转的,详细介绍了恢复方法和潜在的生产环境危害。

本文讨论了在PostgreSQL,MySQL和MongoDB等各个数据库中的JSON列上创建索引,以增强查询性能。它解释了索引特定的JSON路径的语法和好处,并列出了支持的数据库系统。

文章讨论了使用准备好的语句,输入验证和强密码策略确保针对SQL注入和蛮力攻击的MySQL。(159个字符)
