SQL 中视图和物化视图的区别
来源:tutorialspoint
时间:2023-08-28 09:17:05 102浏览 收藏
来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习数据库相关编程知识。下面本篇文章就来带大家聊聊《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 中视图和物化视图的区别》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
308 收藏
-
381 收藏
-
101 收藏
-
499 收藏
-
361 收藏
-
113 收藏
-
434 收藏
-
335 收藏
-
242 收藏
-
449 收藏
-
127 收藏
-
163 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习