View (SQL): Difference between revisions

Content deleted Content added
Talchu (talk | contribs)
m added a reference for benefits of Views
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
 
(4 intermediate revisions by 4 users not shown)
Line 1:
{{Short description|Database stored query result set}}
{{UnreferencedMore citations needed|date=MarchDecember 20202023}}
In a [[database]], a '''view''' is the [[result set]] of a ''stored'' [[Query language|query]], whichthat canpresents bea queriedlimited inperspective of the samedatabase manner asto a persistent database collection objectuser.<ref name="mysql-views">{{cite web | url=https://dev.mysql.com/doc/refman/8.0/en/views.html | title=25.5 Using Views | author=<!--Not stated--> | date=2023-12-12 | website=MySQL | publisher=Oracle | access-date=2023-12-12 | quote=Views are stored queries that when invoked produce a result set. A view acts as a virtual table. | archive-url=httphttps://web.archive.org/web/20231123070115/http://dev.mysql.com:80/doc/refman/8.0/en/views.html | archive-date=2023-11-23 | url-status=live }}</ref> This pre-established query command is kept in the [[data dictionary]]. Unlike ordinary ''[[base table]]s'' in a [[relational database]], a view does not form part of the [[database design|physical schema]]: as a result set, it is a virtual table<ref name="mysql-views" /> computed or collated dynamically from data in the database when access to that view is requested. Changes applied to the data in a relevant ''underlying table'' are reflected in the data shown in subsequent invocations of the view.
 
Views can provide advantages over tables:
Line 13:
| ___location = <!-- not stated -->
| publisher = Osborne/McGraw-Hill
| pages = 291-292291–292
| isbn = 0072118458
}}</ref>
* Views can [[Join (SQL)|join]] and simplify multiple tables into a single virtual table.<ref name="SQL-reference-groff-weinberg" />
* Views can act as aggregated tables, where the [[database engine]] aggregates data ([[summation|sum]], [[average]], etc.) and presents the calculated results as part of the data.
* Views can hide the complexity of data. For example, a view could appear as Sales2000Sales2020 or Sales2001Sales2021, transparently [[Partition (database)|partitioning]] the actual underlying table.
* Views take very little space to store; the database contains only the definition of a view, not a copy of all the data that it presents.
* StructuresViews structure data in a way that classes of users find natural and intuitive.<ref name="SQL-reference-groff-weinberg"/>
Just as a [[function (computing)|function]] (in programming) can provide [[Abstraction (computer science)|abstraction]], so can a database view. In another parallel with functions, database users can manipulate nested views, thus one view can aggregate data from other views. Without the use of views, the [[Database normalization|normalization]] of databases above [[second normal form]] would become much more difficult. Views can make it easier to create lossless join decomposition.
 
Line 26:
 
== Read-only vs. updatable views ==
Views can be defined as [[file system permissions|read-only]] or updatable. If the database system can determine the reverse mapping from the view schema to the schema of the underlying base tables, then the view is updatable. [[Insert (SQL)|INSERT]], [[Update (SQL)|UPDATE]], and [[Delete (SQL)|DELETE]] operations can be performed on updatable views. Read-only views do not support such operations because the DBMS cannot map the changes to the underlying base tables. A view update is done by key preservation.
 
Some systems support the definition of INSTEAD OF [[Database trigger|triggers]] on views. This technique allows the definition of other logic for execution in place of an insert, update, or delete operation on the views. Thus database systems can implement data modifications based on read-only views. However, an INSTEAD OF trigger does not change the read-only or updatable property of the view itself.
 
==Materialized views==
{{detailsfurther|Materialized view}}
 
Various [[database management system]]s have extended the views from read-only subsets of [[data]], particularly [[materialized view]]s: pre-executed, non-virtual views commonly used in [[Data warehouse|data warehousing]]. They give a static snapshot of the data and may include data from remote sources. The accuracy of a materialized view depends on the frequency of trigger mechanisms behind its updates.
Line 88:
 
{{Databases}}
 
==References==
{{Reflist}}
 
{{DEFAULTSORT:View (Database)}}