Thursday, August 3, 2017

Oracle "View"


View = A dummy table. if a view contains only data from one table . then , the data update in the table will auto-update the data in view.



Grammar

Create [or replace] [force] view view1 as select * from  student [ with check option] [with read only]; 

force : create a view by force , don't care whether the table is existed or not!
with check option : don't allow any update to make the data in view increase or decrease.
with read only : don't allow any update , read only.

Concatenating view :

Join multiple tables to create a view is called cancatenating view, you can do DML to columns in key-preserved table but can't update columns in non key-preserved table.

key-preserved table : the primary key in one table is regared as the primary key in view.
non key-preserved table : the primary key in the rest tables are not regarded as the primary key of view.

Create view view_student_address1 as select s.sno  sno1,s.sname, s.sno sno2, a.zz from student1 s, address a where s.sno = a.sno;  // create a concatenating view


Update view_student_address1 set sno1 = 12 where sno1 = 2; // can update, because it belongs to key-preserved table

If you want to update the data in non key-preserved table,  the only thing you can do is to use Oracle's instead of trigger, it can manipulate any view.

Hope my article can help you in your work.

No comments:

Post a Comment

Add Loading Spinner for web request.

when web page is busily loading. normally we need to add a spinner for the user to kill their waiting impatience. Here, 2 steps we need to d...