View management database up to the dream

View management database up to the dream

View (view), also known as virtual table, do not take up physical space, because the view definition statement itself or to be stored in the data dictionary. View only logical table, each time you use, but re-execute the SQL.
There is something called materialized views (materialized view), also known as materialized views, it contains data, take up storage space.

1, the view management
view is obtained from one or more of the real tables, these tables of data stored in the database. Those tables for generating a view of the base table is called the view, a view can be generated from another view.

Create test table, and an insert test data
Create Table tab_view_cs (int ID, name VARCHAR (10), Sex VARCHAR (10), bithdate DATE);
INSERT INTO tab_view_cs values (100, 'Test', 'FEMALE', '2019- 7-13 ');
View management database up to the dream

Create a view of the test, the results of the query view
the Create or the replace the SELECT AS View tab_view_cs_v the above mentioned id, name from tab_view_cs the WHERE Sex = 'FEMALE';
the SELECT name from tab_view_cs_v;
View management database up to the dream

Delete view
drop view tab_view_cs_v;
View management database up to the dream

2, materialized views
materialized view (materialized view), also known as materialized view, it contains data, take up storage space.
Create two test table
Create Table tab_mview_cs_1 (int V1, V2 char (10), V3 VARCHAR (20 is), V4 DATE);
Create Table tab_mview_cs_2 (int T1, T2 char (10), T3 VARCHAR (20 is), T4 DATE) ;
View management database up to the dream

Creating materialized views, materialized views and query results
create materialized view tab_mview_cs_mv (v1, v2 , v3, v4) build immediate refresh complete enable query rewrite as select tab_mview_cs_1.v1 as v1, tab_mview_cs_1.v2 as v2, tab_mview_cs_1.v3 as v3, tab_mview_cs_2 .t4 as v4 from tab_mview_cs_1, tab_mview_cs_2 where tab_mview_cs_1.v1 = tab_mview_cs_2.t1;

select * from tab_mview_cs_mv;
View management database up to the dream

Modified depending on the view and delete it and then look at the results to see
the ALTER disable a materialized View tab_mview_cs_mv Query rewrite;
drop a materialized View tab_mview_cs_mv;
the SELECT * from tab_mview_cs_mv;
View management database up to the dream

Guess you like

Origin blog.51cto.com/14615334/2463434