Content deleted Content added
cleaned up quite a bit |
added more content |
||
Line 9:
* Views do not incur any extra storage overhead
* Depending on the [[SQL]] engine used, views can provide extra security.
Just like functions (in programming) provide abstraction, views can be used to create abstraction. Also, just like functions, views can be nested, thus one view can aggregate data from other views. Without the use of views it would be much harder to normalise databases above 2nd normal form. Views can make it easier to create lossless join decomposition.
Rows available through a view are not sorted. A view is a relational table, and the relational model states that a table is a set of rows. Since sets are not sorted - per definition - the rows in a view are not ordered either. Therefore, an [[order by (SQL)|ORDER BY]] clause in the view definition is meaningless and the SQL standard ([[SQL:2003]]) does not allow this for the subselect in a CREATE VIEW statement.
Line 20 ⟶ 22:
Various [[database management system]]s have extended the views from read-only subsets of [[data]].
The [[Oracle database]] introduced the concept of [[materialized view]]s, which are pre-executed, non-virtual views commonly used in data warehousing. They are a static snapshot of the data and may include data from remote sources. The accuracy of a materialized view depends on the frequency or trigger mechanisms behind its updates. The equivalent of this in [[Microsoft SQL Server]], introduced in the 2000 version, is an indexed view. DB2 provides so-called ''materialized query tables (MQTs)'' for the same purpose.
== Equivalency ==
A view is equivalent to its source query. When queries are run against views, the query is modified. Ie if there exists a vie named Accounts_view and the content is
<code>SELECT name,
money_received,
money_sent,
( money_received
- money_sent) AS balance,
address,
...
FROM table_customers c
JOIN accounts_table a
ON a.customerid = c.customer_id</code>
The application would simply run a simple query such as:
<code>
SELECT name,
balance
FROM accounts_view</code>
The RDBMS then takes the simple query, replaces the equivalent view, then sends the following to the optimiser:
<pre>
SELECT NAME,
balance
FROM (SELECT name,
money_received,
money_sent,
( money_received
- money_sent) AS balance,
address,
...
FROM table_customers c JOIN accounts_table a
ON a.customerid = c.customer_id
)</pre>
==External links==
|