48. Evaluate the following CREATE TABLE command:
CREATE TABLE order_item
(order_id NUMBER(3),
item_id NUMBER(2),
qty NUMBER(4),
CONSTRAINT ord_itm_id_pk
PRIMARY KEY (order_id,item_id)
USING INDEX
(CREATE INDEX ord_itm_idx
ON order_item(order_id,item_id)))?
Which statement is true regarding the above SQL statement?
A. It would execute successfully and only ORD_ITM_IDX index would be created.
B. It would give an error because the USING INDEX clause cannot be used on a composite primary key.
C. It would execute successfully and two indexes ORD_ITM_IDX and ORD_ITM_ID_PK would be
created.
D. It would give an error because the USING INDEX clause is not permitted in the CREATE TABLE
command.
Answer: A
为啥是A?主键约束与索引有什么关系么?
------解决方案--------------------
默认的,如果是这样的:
CREATE TABLE order_item
(order_id NUMBER(3),
item_id NUMBER(2),
qty NUMBER(4),
CONSTRAINT ord_itm_id_pk
PRIMARY KEY (order_id,item_id));
那么就会创建索引ord_itm_id_pk,因为在oracle里面,如果创建了主键约束,默认自动创建了针对此主键的索引。当然,你可以指定主键约束使用自己创建的特定索引,如题中:ord_itm_idx,这个时候,oracle就不会自动给你创建索引了。
所以选A,只会创建一个索引。