View (SQL): Difference between revisions

Content deleted Content added
Encore007 (talk | contribs)
Added {{Unreferenced}} tag to article (TW)
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 30:
A view is equivalent to its source query. When queries are run against views, the query is modified. For example, if there exists a view named accounts_view with the content as follows:
 
<sourcesyntaxhighlight lang="sql">
accounts_view:
-------------
Line 42:
JOIN accounts_table a
ON a.customer_id = c.customer_id
</syntaxhighlight>
</source>
 
then the application could run a simple query such as:
 
<sourcesyntaxhighlight lang="sql">
Simple query
------------
Line 52:
balance
FROM accounts_view
</syntaxhighlight>
</source>
 
The RDBMS then takes the simple query, replaces the equivalent view, then sends the following to the [[query optimizer]]:
 
<sourcesyntaxhighlight lang="sql">
Preprocessed query:
------------------
Line 69:
FROM table_customers c JOIN accounts_table a
ON a.customer_id = c.customer_id )
</syntaxhighlight>
</source>
 
The optimizer then removes unnecessary fields and complexity (for example: it is not necessary to read the address, since the parent invocation does not make use of it) and then sends the query to the SQL engine for processing.