Although we began our study of SQL by using some very simple queries, at this point we have definitely graduated to some fairly complex ones. Multi-table joins, subqueries, and nested functions can all play a part in the need for long and complicated SQL code. Often, this code is created to be reused numerous times for business needs such as reporting. A view allows us to store a query as a database object so that it is simplified and reusable.
Since views are objects that store queries, we should look at an example of the type of SELECT
statement that can be stored as a view. The following example contains a SQL statement we used in Chapter 5, Combining Data from Multiple Tables to create a reasonably complex multi-table join of employee
, employee_award
, and award
. This is our candidate statement to simplify using a view.
Database views are creating using the CREATE
VIEW
command, as shown in the following example. We use a view to encapsulate the previous...