ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 047-061

047-061

原创 Linux操作系统 作者:jbymy2000 时间:2012-03-18 09:30:28 0 删除 编辑
61. Evaluate the following SQL statements that are issued in the given order:
CREATE TABLE emp
(emp_no NUMBER(2) CONSTRAINT emp_emp_no_pk PRIMARY KEY,
ename VARCHAR2(15),
salary NUMBER(8,2),
mgr_no NUMBER(2) CONSTRAINT emp_mgr_fk REFERENCES emp);
ALTER TABLE emp DISABLE CONSTRAINT emp_emp_no_pk CASCADE;
ALTER TABLE emp ENABLE CONSTRAINT emp_emp_no_pk;
What would be the status of the foreign key EMP_MGR_FK?
A. It would be automatically enabled and deferred.
B. It would be automatically enabled and immediate.
C. It would remain disabled and has to be enabled manually using the ALTER
TABLE command.
D. It would remain disabled and can be enabled only by dropping the foreign
key constraint and recreating it.
Answer: C
CREATE TABLE emp
(emp_no NUMBER(2) CONSTRAINT emp_emp_no_pk PRIMARY KEY,
ename VARCHAR2(15),
salary NUMBER(8,2),
mgr_no NUMBER(2) CONSTRAINT emp_mgr_fk REFERENCES emp);
1:insert into emp values(1,'tt',1,2);
ORA-02291: 违反完整约束条件 (SYS.EMP_MGR_FK)
2:insert into emp values(1,'tt',1,1);
ok
3:ALTER TABLE emp DISABLE CONSTRAINT emp_emp_no_pk CASCADE;
4:insert into emp values(1,'tt',1,3);
ok,说明主键失效,外键也失效
5:delete from emp where emp_no=1 and mgr_no=1;
ALTER TABLE emp ENABLE CONSTRAINT emp_emp_no_pk;
insert into emp values(1,'tt',1,4);
ORA-00001: 违反唯一约束条件 (SYS.EMP_EMP_NO_PK)
说明主键已经生效
insert into emp values(2,'tt',1,4);
ok,说明外键仍然失效
6:alter table emp enable constraint emp_mgr_fk(emp_no);
ORA-02298: 无法验证 (SYS.EMP_MGR_FK) - 未找到父项关键字

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11312660/viewspace-718842/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 047-056
下一篇: 047-063
请登录后发表评论 登录
全部评论

注册时间:2012-01-10

  • 博文量
    416
  • 访问量
    203419