You create a view by issuing the CREATE VIEW statement and specifying the view column names, the table(s) and column(s) from which the view is derived, and data restrictions, if any.
Note: For more information about session management statements, see the CA IDMS SQL Reference Guide.
Note: For a complete discussion of SQL select statements, see the CA IDMS SQL Reference Guide.
When creating a view, you can specify physical attributes that are normally generated automatically. Specifying explicit values for this information allows you to create and maintain views that have identical attributes and can therefore be accessed through a single schema definition.
Care should be exercised when specifying a specific timestamp, since its purpose is to enable the detection of discrepancies between a view and its definition. If explicitly specified, the timestamp should always be set to a new value following a definitional change so that the change is detectable to the run time system.
In the following example, a simple view is defined on the EMPLOYEE table.
create view prod.emp_home_phone
as select emp_id, emp_lname, emp_fname, phone
from prod.employee;
In the following example, a view is defined with the check option to restrict rows that can be updated and inserted. Using the view, the value of DEPT_ID cannot be changed to something other than 'SALES', and new rows must have a DEPT_ID of 'SALES'.
create view hr.sales_employee
as select emp_id, emp_lname, emp_fname, dept_id, emp_ssno
from prod.employee
where dept_id = 'SALES'
with check option;
In the following example, a view is defined with three columns derived from two tables. Since the third column includes both aggregate functions and an arithmetic operation, the CREATE VIEW statement must specify names for the columns in the view.
This view is nonupdatable because the SELECT references more than one table and because the view projects computed values.
create view prod.emp_vacation
(emp_id, dept_id, vac_time)
as select e.emp_id, dept_id, sum(vac_accrued) - sum(vac_taken)
from prod.employee e, prod.benefits b
where e.emp_id = b.emp_id
group by dept_id, e.emp_id;
Note: For more information about SQL syntax, see the CA IDMS SQL Reference Guide.
|
Copyright © 2014 CA.
All rights reserved.
|
|