Views

After a table is created and populated with data it may become necessary to prevent all users from accessing all columns of a table, as required. This will answer data security requirements very well but will give rise to a great deal of redundant data being resident in tables, in the database.
            To reduce redundant data to the minimum possible, oracle allows the creation of an object called a view. A view is mapped to a select sentence, the table on which the view is bases is described in the from clause of the select statement.
            The oracle engine treats a view just as though it was abase table. Hence a view can be queried exactly as though it was a base table however, a query fired on a view will run slower that a query fired on a base table.
            Some views are used only for looking at table data. Other views can be used to insert update and delete table data as well as view data. If a view is used to only look at table data and nothing else the view is called a read only view. A view that is used to look at table data as well as insert update and delete table data is called an updatable view.

 

Reasons to create a view.

Syntax:- create view viewname as select columname,……. From tablename
Where coloumname=exp group by grouping crateria having predicate.
Ex:-     1) create view visionview as select * from vision;
2)Select * from visionview;
3)Create view visionview1 as select eno,sal from vision;
4)Select * from visionview1;
5)Create view visionview2 as select * from vision where sal>2000;
6)Select * from visionview2;

Updatable Views
            Views can also be used for data manipulation i.e. the user can perform the insert, update and delete operations. Views on which data manipulation can be done are called updatable views. When you give an updatable view name in the update, insert or delete sql statement, modifications to data will be passed to the underlying table.
Views defined from single table.

Ex:-     create view visionview3 as select * from vision;
Insert into visionview3 values(700,’rajesh’,2100);
Insert into visionview3 values(700,’prasad’,3211);
Select * from vision;
Update visionview3 set sal=sal+1000 ;
Select * from vision;
Delete from visionview3 where eno=700;
Select * from vision;
Alter table vision add primary key(eno);
Create view visionview4 as select na,sal from vision;

Insert into visionview4 values (‘prasad’,2100);

Ex:-     create view multipleview as select * from vision where eno
            in(select eno from vision3);
            select * from multipleview;
            insert into multipleview values(150,’prasad’,1111);

A view can be created from more than one table . for the purpose of creating the view these tables will be linked by join condition specified in the where clause of the view’s definition.
The behavior on the view will vary for insert,update,delete and select table operations depending upon the following.

Views Defined from Multiple tables which have no referencing clause:-
If a view is created from multiple tables which were not created using a referencing clause, then through the primary key columns as well the not null columns are included in the view definition the view’s behavior will be as follows.

Ex:-     create view multiview as select vision.eno,vision3.sal from vision,vision3;
Select * from multiview;

For
Online Classes

Contact Us: +919885348743