SQL CREATE VIEW

Views can be considered as virtual tables. Generally speaking, a table has a set of definition that sets the structure of the table, and physically stores the data. A view also has a set of definitions, which is built on top of the table(s) or another view (s), and it does not physically store the data.

The syntax for creating a view is as follows:

 

 

“SQL Statement” can be any of the SQL statements we have discussed in this tutorial.

Let’s use a simple example to illustrate. Say we have the following table:

TABLE Customer

 

 

and we want to create a view called V_Customer that contains only the First_Name, Last_Name, and Country columns from this table, we would type in,

 

 

Now we have a view called V_Customer as below:

 

 

We can also use a view to apply joins to two tables. In this case, users only see one view rather than two tables when they need to combine the information from these two tables. Let’s say we have the following two tables:
Table Store_Information

 

 

Table Geography

 

 

and we want to build a view that has sales by region information. We would issue the following SQL statement:

 

 

This gives us a view, V_REGION_SALES, that has been defined to store sales by region records. If we want to find out the content of this view, we type in,

 

Result:

REGION SALES
East $700
West $2050