Use with check option in oracle

Source: Internet
Author: User
Tags sql error

If the view definition includes conditions (such as the WHERE clause) and its intention is to ensure that the WHERE clause is applied to any INSERT or UPDATE statements that reference the view, you must use with check option to define the view. This option ensures the integrity of the data being modified in the database. If conditions are violated during the INSERT or UPDATE operation, an SQL error is returned.
The following is an example of using the with check option view definition. To always CHECK the conditions, with check option is required. In this case, we want to ensure that DEPT is always 10. This limits the input values of the DEPT column. When a new value is inserted using a view, the with check option is always enforced.
Copy codeThe Code is as follows:
Create view EMP_VIEW2
(EMPNO, EMPNAME, DEPTNO, JOBTITLE, HIREDATE)
As select id, NAME, DEPT, JOB, HIREDATE FROM EMPLOYEE
Where dept = 10
With check option;
If this clause does not exist, a user using this view may update a record so that it does not belong to this view. For example, the following SQL statement may cause some problems.
UPDATE EMP_VIEW2 set dept = 20 where dept = 10;
The result of this statement is that the view does not contain any records now, because Department 10 no longer has employees.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.