Examples—Create View Statement
The following are create view statement examples:
1. Define a view of employee data including names, salaries, and name of the manager.
create view empdpt (ename, sal, dname)
as select employee.name, employee.salary,
dept.name
from employee, dept
where employee.mgr = dept.mgr;
2. Define a view that uses aggregate functions to display the number of open orders and the average amount of the open orders for sales representative that has orders on file. This view is not updatable (because it uses aggregate functions).
create view order_statistics
(sales_rep, order_count, average_amt)
as select salesrep, count(*), avg(ord_total)
from open_orders
group by sales_rep;
3. Define an updatable view showing the employees in the southern division. Specify check option to prevent any update that changes the region or adds an employee from another region.
create view southern_emps
as select * from employee
where region = 'South'
with check option;