1. 程式人生 > >2018年oracle認證OCP考試052新題解析-192

2018年oracle認證OCP考試052新題解析-192

192.

You execute this command.

SQL> DROP TABLE scott.item CASCADE CONSTRAINTS;

The ITEM table has a primary key that is referenced by a foreign key in the ORDERS table RECYCLEBIN IS enabled.

Which three statements are true ?

A) The ITEM table is moved to the RECYCLEBIN.

B) The ITEM table is dropped.

C) The foreign constraint on the ORDERS table is dropped.

D) The foreign constraint on the ORDERS table is disabled.

E) The ORDERS table is dropped.

F) The ORDERS table is moved to the RECYCLEBIN.

G) The foreign constraint on the ORDERS table is moved to the RECYCLEBIN.

解析:

--主表P,又稱父表

create table p(pid number primary key,pname varchar2(10));

--從表C,又稱子表,即引用主表主鍵作為其外來鍵的表

create table c(

did number primary key,

pid number ,

cnt number,

constraint cpk FOREIGN KEY (pid) REFERENCES p(pid));

insert into p values (1,'a');

insert into p values (2,'b');

commit;

insert into c values (100,1,1);

insert into c values (200,2,1);

commit;

則當刪除p表時,如不特殊說明,則 drop table p 系統會出現如下錯誤警告的資訊而不會允許執行。

SQL> drop table p;

drop table p

           *

第 1 行出現錯誤:

ORA-02449: 表中的唯一/主鍵被外來鍵引用

解決辦法,使用語句可以刪除從表(或稱子表)的constraint,從而可實現主表(或稱父表)的drop;

SQL> Drop table p cascade constraints;

表已刪除。

SQL> Flashback table p to before drop;

閃回完成

insert into c values (300,3,1);

SQL> commit;

SQL> select * from p;

       PID PNAME

---------- ----------

         1 a

         2 b

SQL> select * from c;

       DID        PID        CNT

---------- ---------- ----------

       100          1          1

       200          2          1

       300          3          1

SQL> insert into p values (1,'c');

第 1 行出現錯誤:

ORA-00001: 違反唯一約束條件 (TEST.BIN$YFRv1nd6QU+BOVRlpS8pKw==$0)

SQL> insert into c values (200,2,1);

第 1 行出現錯誤:

ORA-00001: 違反唯一約束條件 (TEST.SYS_C0011128)

更多2018年oracle認證OCP考試071新題解析討論請加入QQ群:479384490

更多2018年oracle認證OCP考試052新題解析討論請加入QQ群:479384490

更多2018年oracle認證OCP考試053新題解析討論請加入QQ群:479384490