Views
Views
A view takes the output of the query and treats it as a table, therefore a view can
be thought of as a stored query or a virtual table.
TYPES
1 Simple view
2 Complex view
Simple view can be created from one table where as complex view can be created
from multiple tables.
WHY VIEWS?
Ex:
SQL> Create view dept_v as select *from dept with read only;
SQL> Create view dept_v as select deptno, sum(sal) t_sal from emp group by
deptno;
SQL> Create view stud as select rownum no, name, marks from student;
SQL> Create view student as select *from student1 union select *from
student2;
SQL> Create view stud as select distinct no,name from student;
1 View with not null column -- insert with out not null column not possible
-- update not null column to null is not possible
-- delete possible
2 View with out not null column which was in base table -- insert not possible
-- update, delete possible
3 View with expression -- insert , update not possible
-- delete possible
4 View with functions (except aggregate) -- insert, update not possible
-- delete possible
5 View was created but the underlying table was dropped then we will get
the message like “ view has errors ”.
6 View was created but the base table has been altered but still the view was
with the initial definition, we have to replace the view to affect the
changes.
7 Complex view (view with more than one table) -- insert not possible
-- update, delete possible (not
always)
SQL> Create view stud as select *from student where marks = 500 with check
option
constraint Ck;
- Insert possible with marks value as 500
- Update possible excluding marks column
- Delete possible
DROPPING VIEWS