Which two statements are true regarding views? (Choose two.)
A.
A simple view in which column aliases have been used cannot be updated.
B.
Rows cannot be deleted through a view if the view definition contains the DISTINCT keyword.
C.
Rows added through a view are deleted from the table automatically when the view is dropped.
D.
The OR REPLACE option is used to change the definition of an existing view without dropping
and recreating it.
E.
The WITH CHECK OPTION constraint can be used in a view definition to restrict the columns
displayed through the view.
B is not true.
If you have a PRIMARY KEY on a table and this primary key is used in view definition (along with the DISTINCT keyword), it is possible to delete from that view/underlying table:
SQL> CREATE TABLE emp_bonuses(empno NUMBER PRIMARY KEY, bonus NUMBER);
Table created.
SQL> insert into emp_bonuses VALUES(1000, 1000);
1 row created.
SQL> insert into emp_bonuses VALUES (2000, 2000);
1 row created.
SQL> CREATE VIEW emp_bons AS SELECT DISTINCT empno, bonus FROM emp_bonuses;
View created.
SQL> SELECT * FROM emp_bons;
EMPNO BONUS
———- ———-
1000 1000
2000 2000
SQL> DELETE FROM emp_bons WHERE EMPNO = 2000;
1 row deleted.
SQL> SELECT * FROM emp_bons;
EMPNO BONUS
———- ———-
1000 1000
DELETE FROM emp_bons WHERE EMPNO = 2000
Error at Command Line : 130 Column : 13
Error report –
SQL Error: ORA-01732: data manipulation operation not legal on this view
01732. 00000 – “data manipulation operation not legal on this view”
*Cause:
*Action:
when the primary key is not specified in the table creation…
@sri, totally agree, thanks