【正文】
om employee where 工資 2022 go insert into v_employee2 values( 002,’王則’ ,30,’f’,1000) go select * from employee go select * from v_employee2 go 插入數(shù)據(jù)記錄 例 79 在例子 78的基礎上添加 WITH CHECK OPTION選項。 程序清單如下: create view v_employee3 as select * from employee where 工資 2022 with check option go insert into v_employee3 values( 002,’王則’ ,30,’f’,1000) go select * from v_employee3 go 運行該程序將顯示如下出錯信息: Server: Msg 550, Level 16, State 1, Line 1 The attempted insert or update failed because the target view either specifies WITH CHECK OPTION or spans a view that specifies WITH CHECK OPTION and one or more rows resulting from the operation did not qualify under the CHECK OPTION constraint. The statement has been terminated. 更新和刪除數(shù)據(jù)記錄 使用視圖可以更新數(shù)據(jù)記錄,但應該注意的是,更新的只是數(shù)據(jù)庫中的基表。使用視圖刪除記錄,可以刪除任何基表中的記錄,直接利用 DELETE語句刪除記錄即可。但應該注意,必須指定在視圖中定義過的字段來刪除記錄。 ?例 710 創(chuàng)建了一個基于表 employees的視圖 v_employees,然后通過該視圖修改表 employees中的記錄。 程序清單如下: create view v_employees as select * from employees update v_employees set name=’張然’ where name=’張三’ ?例 711 利用視圖 v_employees刪除表 employees中姓名為張然的記錄。 程序清單如下: delete from v_employees where name=’張然’