创建索引的另一种方式(index)
2013-08-18 12:06
357 查看
今天看ocp题库,发现了一个新知识点,原来索引还可以这样创建;
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 INDEXord_itm_idx ON order_item(order_id,item_id)));
表创建成功以后,在列order_id和item_id上只有一个普通索引ord_itm_idx;如果不用using index 子句,那么只会创建一个与主键约束一样名字的唯一索引;
当然也可以先创建表,然后创建一个索引,再添加一个主键约束并用using index子句使用哪个已有的索引;
下面两道题目说明了这两个知识点:
QUESTION 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
QUESTION 41
View the Exhibit and examine the structure of the EMP table.
You executed the following command to add a primary key to the EMP table:
ALTER TABLE emp
ADD CONSTRAINT emp_id_pk PRIMARY KEY (emp_id)
USING INDEX emp_id_idx;
Which statement is true regarding the effect of the command?
A. The PRIMARY KEY is created along with a new index.
B. The PRIMARY KEY is created and it would use an existing unique index.
C. The PRIMARY KEY would be created in a disabled state because it is using an existing index.
D. The statement produces an error because the USING clause is permitted only in the CREATE TABLE command.
Answer: B
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 INDEXord_itm_idx ON order_item(order_id,item_id)));
表创建成功以后,在列order_id和item_id上只有一个普通索引ord_itm_idx;如果不用using index 子句,那么只会创建一个与主键约束一样名字的唯一索引;
当然也可以先创建表,然后创建一个索引,再添加一个主键约束并用using index子句使用哪个已有的索引;
下面两道题目说明了这两个知识点:
QUESTION 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
QUESTION 41
View the Exhibit and examine the structure of the EMP table.
You executed the following command to add a primary key to the EMP table:
ALTER TABLE emp
ADD CONSTRAINT emp_id_pk PRIMARY KEY (emp_id)
USING INDEX emp_id_idx;
Which statement is true regarding the effect of the command?
A. The PRIMARY KEY is created along with a new index.
B. The PRIMARY KEY is created and it would use an existing unique index.
C. The PRIMARY KEY would be created in a disabled state because it is using an existing index.
D. The statement produces an error because the USING clause is permitted only in the CREATE TABLE command.
Answer: B
相关文章推荐
- mysql建立索引的优缺点|创建索引alter或create索引分类(PRIMARY KEY,UNIQUE KEY,FULLTEXT,INDEX)作用查看索引show index from table
- ACCESS 创建表及索引方式
- MySQL索引的创建、删除 index creat/delete
- SQL Server 创建索引(index)
- 创建索引的两种方式(重点)
- ElasticSearch创建索引(index)和添加映射(mapping)
- Python--MySql(主键的创建方式、存储引擎、存储过程、索引、pymsql)
- Lucene索引创建之域选项介绍,Field.Store和Fiele.Index
- lucene创建索引的几种方式(一)
- mysql创建index索引
- Lucene索引创建之域选项介绍,Field.Store和Fiele.Index
- 另一种方式解决myeclipse10创建activiti diagram文件报错
- MySQL下使用Inplace和Online方式创建索引的教程
- 线程:创建线程有两种方式,一种是继承Thread类,另一种是实现Runnable接口。代码如下:
- Scripts:创建索引组织表例子example_create_index_organized_table.sql
- Oracle之索引的创建方式
- Delegate的另一种创建方式
- SQL大圣之路笔记——SQL 创建索引 index
- Hbase创建索引:Secondary index not enabled. Configure hbase.use.secondary.index to true
- 单链表的创建、插入、删除;创建采用两种不同的方式:一种是从表头到表尾,另一种是从表尾到表头!