A view is a database object that provides restricted access to the table data
Creating a view
When we execute a query on the view, it will access the data from the base table
If we drop the base table, the views are not dropped but they will become invalid
We can perform DML’s on the views which will affect the base table
Does the view improve the performance?
View does not improve the performance as they will not store the data
Modifying a view
Advantages
3. Complex and long queries can be placed in a view for easier reference
Create view v5
As
Select ename…
Union
Select ename… From emp Group by ename Having count(*)>1
Union
Select pname from prods;
select *from v5;
1. Updatable views
2. Non-updatable views
3. Simple views
4. Complex views
5. Read-only views
6. Force views
JOIN condition
Simple Views & Complex Views
SUBQUERY
SET operators
JOIN condition
Note:
Most of the complex views are non-updateable, most of the simple views are updatable.
Read-Only Views
A read-only view will not allow any of the DML statements on it.
Force Views
A force view is helpful in creating views before the tables in the production enviornment
View operations
Renaming
Dropping
Altering
possible, recompiles a view. (RE-CREATES VIEW).(converts INVALID to VALID)
Generally a view inserts the data even though it cannot see it. If we want a view to
‘INSERT’ only the data which it see, then we should use ‘CHECK OPTION’
*** Anyway the update statement is not applicable with CHECK option
create view v1
(empno number primary key, ename)
as
select empno, ename from emp;