oracle中的视图


create table a(
id number primary key,
name varchar2(20)
);
create table b(
id number,
name varchar2(20),
aid number references a(id)
);

insert into a values(1,'1');
insert into b values(1,'aaa',1);

如果 create view vi_new as select * from a

在视图vi_new 上做任何 dml操作都会修改 对应的基表中的数据

因为视图就是一个指针

测试 若果drop table 基表  视图同时也会报错 说明 视图不是单独存在的 而是指向基表的

如果 create view vi_new as select t.a,s.name from A t,B s where t.a=s.id

这样就只能进行查询操作了  进行增删改就会跑错

视图的优点

      1.对数据库的访问,因为视图可以有选择性的选取数据库里的一部分。 

      2.用户通过简单的查询可以从复杂查询中得到结果。 

      3.维护数据的独立性,试图可从多个表检索数据。 

      4.对于相同的数据可产生不同的视图。 

原文地址:https://www.cnblogs.com/liaomin416100569/p/9331698.html