檢視中with check option的作用是什麼?

iSQlServer發表於2009-08-12
create   view   IS_student   
  as   
  select   sno,sname,sage   
  from   student   
  where   sdept='IS'   
  with   check   option;   
  加上了with   check   option;後,不能執行插入操作:   
    
  insert   into   is_student   
  values('95100','李娜',12)   
    
  什麼原因?不加上with   check   option則可以!  


with   check   option可以這麼解釋:通過檢視進行的修改,必須也能通過該檢視看到修改後的結果。比如你insert,那麼加的這條記錄在重新整理檢視後必須可以看到; 如果修改,修改完的結果也必須能通過該檢視看到;如果刪除,當然只能刪除檢視裡有顯示的記錄。   
    
而你只是查詢出sdept='is'的紀錄,你插入的根本不符合sdept='is'呀,所以就不行

意思就是說在執行Insert的時候,預設情況下sdept是'IS',才滿足with   check   option是嗎?   
    
DBMS不會自動加上Sdept='IS'嗎?因為在檢視IS_student是選擇所有是‘IS’的學生的啊!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16436858/viewspace-612026/,如需轉載,請註明出處,否則將追究法律責任。

相關文章