SQL sql中View和table的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6015175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:34:05  来源:igfitidea点击:

Difference between View and table in sql

sqlview

提问by Mahesh KP

Possible Duplicate:
Difference Between Views and Tables in Performance

可能的重复:
视图和表的性能差异

What is the main difference between view and table in SQL. Is there any advantage of using views instead of tables.

SQL 中视图和表的主要区别是什么。使用视图而不是表格有什么好处。

回答by Aaron Digulla

A table contains data, a view is just a SELECTstatement which has been saved in the database (more or less, depending on your database).

表包含数据,视图只是SELECT已保存在数据库中的语句(或多或少,取决于您的数据库)。

The advantage of a view is that it can join data from several tables thus creating a new view of it. Say you have a database with salaries and you need to do some complex statistical queries on it.

视图的优点是它可以连接来自多个表的数据,从而创建它的新视图。假设您有一个包含工资的数据库,您需要对其进行一些复杂的统计查询。

Instead of sending the complex query to the database all the time, you can save the query as a view and then SELECT * FROM view

您可以将查询保存为视图,而不是一直将复杂的查询发送到数据库 SELECT * FROM view

回答by Senthil_Arun

Table:Table is a preliminary storage for storing data and information in RDBMS. A table is a collection of related data entries and it consists of columns and rows.

表:表是RDBMS中存储数据和信息的初步存储。表是相关数据条目的集合,由列和行组成。

View:A view is a virtual table whose contents are defined by a query. Unless indexed, a view does not exist as a stored set of data values in a database. Advantages over table are

视图:视图是一个虚拟表,其内容由查询定义。除非索引,否则视图不会作为数据库中存储的一组数据值存在。与桌子相比的优势是

  • We can combine columns/rows from multiple table or another view and have a consolidated view.
  • Views can be used as security mechanisms by letting users access data through the view, without granting the users permissions to directly access the underlying base tables of the view
  • It acts as abstract layer to downstream systems, so any change in schema is not exposed and hence the downstream systems doesn't get affected.
  • 我们可以将多个表或另一个视图中的列/行组合起来,并拥有一个统一的视图。
  • 视图可以作为安全机制,让用户通过视图访问数据,而不授予用户直接访问视图底层基表的权限
  • 它充当下游系统的抽象层,因此不会暴露架构中的任何更改,因此下游系统不会受到影响。

回答by SuperGuy10

A view is a virtual table. A view consists of rows and columns just like a table. The difference between a view and a table is that views are definitions built on top of other tables (or views), and do not hold data themselves. If data is changing in the underlying table, the same change is reflected in the view. A view can be built on top of a single table or multiple tables. It can also be built on top of another view. In the SQL Create View page, we will see how a view can be built.

Views offer the following advantages:

  1. Ease of use: A view hides the complexity of the database tables from end users. Essentially we can think of views as a layer of abstraction on top of the database tables.

  2. Space savings: Views takes very little space to store, since they do not store actual data.

  3. Additional data security: Views can include only certain columns in the table so that only the non-sensitive columns are included and exposed to the end user. In addition, some databases allow views to have different security settings, thus hiding sensitive data from prying eyes.

视图是一个虚拟表。视图就像表一样由行和列组成。视图和表之间的区别在于,视图是建立在其他表(或视图)之上的定义,并且本身不保存数据。如果基础表中的数据发生变化,视图中也会反映相同的变化。视图可以建立在单个表或多个表之上。它也可以建立在另一个视图之上。在 SQL 创建视图页面中,我们将看到如何构建视图。

视图具有以下优点:

  1. 易用性:视图对最终用户隐藏了数据库表的复杂性。本质上,我们可以将视图视为数据库表之上的抽象层。

  2. 节省空间:视图只需要很少的空间来存储,因为它们不存储实际数据。

  3. 附加数据安全性:视图只能包含表中的某些列,以便仅包含非敏感列并向最终用户公开。此外,一些数据库允许视图具有不同的安全设置,从而隐藏敏感数据不被窥探。

Answer from:http://www.1keydata.com/sql/sql-view.html

答案来自:http: //www.1keydata.com/sql/sql-view.html

回答by Haris

In view there is not any direct or physical relation with the database. And Modification through a view (e.g. insert, update, delete) is not permitted.Its just a logical set of tables

鉴于与数据库没有任何直接或物理关系。并且不允许通过视图进行修改(例如插入、更新、删除)。它只是一组逻辑表

回答by Deepak Ranjan Mohanty

A view helps us in get rid of utilizing database space all the time. If you create a table it is stored in database and holds some space throughout its existence. Instead view is utilized when a query runs hence saving the db space. And we cannot create big tables all the time joining different tables though we could but its depends how big the table is to save the space. So view just temporarily create a table with joining different table at the run time. Experts,Please correct me if I am wrong.

视图帮助我们摆脱一直在使用数据库空间。如果您创建一个表,它会存储在数据库中并在其存在期间保留一些空间。而是在查询运行时使用视图,从而节省数据库空间。我们不能一直创建大表,尽管我们可以加入不同的表,但这取决于表有多大以节省空间。所以视图只是临时创建一个表,在运行时加入不同的表。专家,如果我错了,请纠正我。

回答by Hari

Table:

桌子:

Table stores the data in database and contains the data.

表将数据存储在数据库中并包含数据。

View:

看法:

View is an imaginary table, contains only the fields(columns) and does not contain data(row) which will be framed at run time Views created from one or more than one table by joins, with selected columns. Views are created to hide some columns from the user for security reasons, and to hide information exist in the column. Views reduces the effort for writing queries to access specific columns every time Instead of hitting the complex query to database every time, we can use view

视图是一个虚构的表,只包含字段(列),不包含将在运行时框架的数据(行)。创建视图是为了出于安全原因对用户隐藏某些列,并隐藏列中存在的信息。视图减少了每次编写查询以访问特定列的工作量 我们可以使用视图而不是每次都对数据库执行复杂的查询

回答by nagnath

SQL Views:

SQL 视图:

View is a virtual table based on the result-set of an SQL statement and that is Stored in the database with some name.

视图是基于 SQL 语句结果集的虚拟表,它以某个名称存储在数据库中。

SQL Table:

SQL表:

SQL table is database instance consists of fields (columns), and rows.

SQL 表是由字段(列)和行组成的数据库实例。

Check following post, author listed around seven differences between views and table

检查以下帖子,作者列出了视图和表之间的七个差异

https://codechef4u.com/post/2015/09/03/sql-views-vs-tables

https://codechef4u.com/post/2015/09/03/sql-views-vs-tables