--- View with check option ----

Source: Internet
Author: User

You can use a view with the check option to operate the base table (only for a single table, the view connecting multiple tables is looking for an answer). The following conclusions are available:
First, the view only operates on the data that can be queried. For the data that cannot be queried by the view, even if the base table exists, it cannot be operated through the view.
1. For update, with check option is available. Make sure that the data is queried by the view after update.
2. For Delete, all with check options are the same
4. With check option for insert, make sure that data is queried by the view after insert.
For views without where clauses, using with check option is redundant.

The conclusion is as follows:
-- Create a table
Create Table EMP (
ID number (5, 0 ),
Name varchar2 (12 ),
Address varchar2 (12)
);
Insert into EMP values (5, 'values 3', 'values West ');
Insert into EMP values (6, 'Li si', 'beijing ');
Insert into EMP values (7, 'wang wu', 'shan dong ');

-- Create a view with check Option
Create view emp_view
As
Select * from EMP where id = 5
With check option;

-- Create a view without the with check option Option
Create view emp_view2
As
Select * from EMP where id = '5'
-- Update operation
Update emp_view set name = 'chen 6' where id = 6;-although the base table has records with ID = 6, emp_view cannot be viewed, so this modification will not affect the content of the base table.
Update emp_view Set ID = 6 where id = 5; -- View with check option where-clause violation error
Update emp_view2 Set ID = 6 where id = 5; -- successfully executed/plain row
-- Conclusion:
-- For update, if the with option is used, only the record of the View appears. For update with the whih option, make sure that the change still appears in the view.

-- Change data back to prototype
Update EMP Set ID = 5 where name = 'prop 3 ';

-- Delete operation
Delete emp_view where id = '5'
-- Conclusion:
-- The with option is the same for Delete.

-- Insert operation
Insert into emp_view values (8, 'King', 'jiang yun'); -- View with check option where-clause violation error
Insert into emp_view2 values (8, 'King', 'jiang yun'); -- execution successful
-- Conclusion:
-- For insert, The with option is available. The inserted data must be displayed in the view. For views without the with option, any records that do not violate the constraints can be inserted.

You can use a view with the check option to operate the base table (only for a single table, the view connecting multiple tables is looking for an answer). The following conclusions are available:
First, the view only operates on the data that can be queried. For the data that cannot be queried by the view, even if the base table exists, it cannot be operated through the view.
1. For update, with check option is available. Make sure that the data is queried by the view after update.
2. For Delete, all with check options are the same
4. With check option for insert, make sure that data is queried by the view after insert.
For views without where clauses, using with check option is redundant.

The conclusion is as follows:
-- Create a table
Create Table EMP (
ID number (5, 0 ),
Name varchar2 (12 ),
Address varchar2 (12)
);
Insert into EMP values (5, 'values 3', 'values West ');
Insert into EMP values (6, 'Li si', 'beijing ');
Insert into EMP values (7, 'wang wu', 'shan dong ');

-- Create a view with check Option
Create view emp_view
As
Select * from EMP where id = 5
With check option;

-- Create a view without the with check option Option
Create view emp_view2
As
Select * from EMP where id = '5'
-- Update operation
Update emp_view set name = 'chen 6' where id = 6;-although the base table has records with ID = 6, emp_view cannot be viewed, so this modification will not affect the content of the base table.
Update emp_view Set ID = 6 where id = 5; -- View with check option where-clause violation error
Update emp_view2 Set ID = 6 where id = 5; -- successfully executed/plain row
-- Conclusion:
-- For update, if the with option is used, only the record of the View appears. For update with the whih option, make sure that the change still appears in the view.

-- Change data back to prototype
Update EMP Set ID = 5 where name = 'prop 3 ';

-- Delete operation
Delete emp_view where id = '5'
-- Conclusion:
-- The with option is the same for Delete.

-- Insert operation
Insert into emp_view values (8, 'King', 'jiang yun'); -- View with check option where-clause violation error
Insert into emp_view2 values (8, 'King', 'jiang yun'); -- execution successful
-- Conclusion:
-- For insert, The with option is available. The inserted data must be displayed in the view. For views without the with option, any records that do not violate the constraints can be inserted.

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.