OCP-1Z0-051-V9.02-47题

来源:互联网 发布:知乎 墨子号 编辑:程序博客网 时间:2024/06/13 22:57
47. View the Exhibit and examine the structure of ORD and ORD_ITEMS tables.
The ORD_NO column is PRIMARY KEY in the ORD table and the ORD_NO and ITEM_NO columns are
composite PRIMARY KEY in the ORD_ITEMS table.
Which two CREATE INDEX statements are valid? (Choose two.) 
A. CREATE INDEX ord_idx1 
ON ord(ord_no);
B. CREATE INDEX ord_idx2 
ON ord_items(ord_no);
C. CREATE INDEX ord_idx3 
ON ord_items(item_no);
D. CREATE INDEX ord_idx4 
ON ord,ord_items(ord_no, ord_date,qty);
Answer: BC
答案解析:
参考:http://blog.csdn.net/rlhua/article/details/12780775
实验验证:
1、创建两张表
创建ord表
sh@TESTDB> create table ord
  2  (ord_no number(2) not null,
  3  ord_date date,
  4  cust_id number(4));
 
Table created.
创建ord_items表
sh@TESTDB> create table ord_items
  2  (ord_no number(2) not null,
  3  item_no number(3) not null,
  4  qty number(8,2));
 
Table created.
 2、增加约束,使其满足题意
 
sh@TESTDB> alter table ord add constraint pk_ord primary key(ord_no);
 
Table altered.
 
sh@TESTDB> alter table ord_items add constraint pk_ord_item primary key(ord_no,item_no);
 
Table altered.
 
A错误,因为ord_no是主键,已经自动创建了一个唯一的索引,故不能再创建索引。
sh@TESTDB> create index ord_idx1 on ord(ord_no);
create index ord_idx1 on ord(ord_no)
                             *
ERROR at line 1:
ORA-01408: such column list already indexed

 
B,C正确,虽然在两列创建了主键约束,即自动创建的唯一索引是按照两列的组合来创建的,所以单列是可以创建索引的,
sh@TESTDB> CREATE INDEX ord_idx2 
  2  ON ord_items(ord_no);
 
Index created.


sh@TESTDB> CREATE INDEX ord_idx3 
  2  ON ord_items(item_no);
 
Index created.
 

 
D错误,属于语法错误,不能两张表同时建立索引
 
sh@TESTDB> CREATE INDEX ord_idx4 
  2  ON ord,ord_items(ord_no, ord_date,qty);
ON ord,ord_items(ord_no, ord_date,qty)
      *
ERROR at line 2:
ORA-00906: missing left parenthesis
原创粉丝点击