——-視圖with check option選項——————-

來源:互聯網
上載者:User

通過有with check option選項的視圖操作基表(只是面對單表,對串連多表的視圖正在尋找答案),有以下結論:
首先視圖只操作它可以查詢出來的資料,對於它查詢不出的資料,即使基表有,也不可以通過視圖來操作。
1.對於update,有with check option,要保證update後,資料要被視圖查詢出來
2.對於delete,有無with check option都一樣
4.對於insert,有with check option,要保證insert後,資料要被視圖查詢出來
對於沒有where 子句的視圖,使用with check option是多餘的。

以例子驗證結論:
--建立表
create table emp(
    id number(5,0),
    name varchar2(12),
    address varchar2(12)
);
insert into emp values (5,'張三','廣西');
insert into emp values (6,'李四','北京');
insert into emp values (7,'王五','山東');

--建立帶with check option的視圖
create view emp_view
as
select * from emp where id=5
with check option;

--建立沒有with check option的視圖
create view emp_view2
as
select * from emp where id='5'
--update 操作
update  emp_view set  name='陳六' where id=6;-,雖然基表有id=6的記錄,但emp_view無法查看到,所以這個修改不會影響基表內容
update  emp_view set  id=6 where id=5; --出現 view WITH CHECK OPTION where-clause violation錯誤
update  emp_view2 set id=6 where id=5; --成功執/plain行
--結論:
--對於update,有無with選項都是只更改視圖出現的記錄,對有whih選項的update,要保證更改後仍可以出現在視圖中

--把資料改回原型
update  emp set id=5 where name='張三';

--delete操作
delete emp_view where id='5'
--結論:
--對於delete,有無with選項是一樣的。

--insert操作
insert into emp_view values (8,'王','江蘇');--出現 view WITH CHECK OPTION where-clause violation錯誤
insert into emp_view2 values (8,'王','江蘇');--執行成功
--結論:
--對於insert,有with選項,插入的資料要最終要可以顯示在視圖中,對於無with選項的視圖可以插入任何不違反約束的記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.