OCP考题解析_007:unique约束和索引
OCP考题解析_007:unique约束和索引
数据库在创建unique constraint的同时,强制创建或者重用列上的索引
www.zzzyk.com
① 如果之前列上没有索引,那么强制创建的索引是unique index;
此时,索引名和约束名是相同的,并且该索引不能删除,当删除unique constraint 时,unique index 会级联删除
② 如果列上已经存在索引,就重用之前的索引,并且不会改变索引的类型,当我们删除约束时,关联的索引不会级联删除
不过,MOS 提供了方法,就是在删除约束时,加上drop index,这样就能一次搞定: www.zzzyk.com
alter table table_name drop constraint constraint_name drop index;
OCP考题:
[sql]
Q: 6 Examine the SQL statement that creates ORDERS table:
CREATE TABLE orders
(SER_NO NUMBER UNIQUE,
ORDER_ID NUMBER,
ORDER_DATE DATE NOT NULL,
STATUS VARCHAR2(10)
CHECK (status IN ('CREDIT', 'CASH')),
PROD_ID NUMBER
REFERENCES PRODUCTS(PRODUCT_ID),
ORD_TOTAL NUMBER,
PRIMARY KEY (order_id, order_date));
For which columns would an index be automatically created when you execute the above SQL statement?
(Choose two.)
A. SER_NO
B. ORDER_ID
C. STATUS
D. PROD_ID
E. ORD_TOTAL
F. composite index on ORDER_ID and ORDER_DATE
Answer: A, F