现在的位置: 首页 > 综合 > 正文

创建索引的两种方式(重点)

2013年10月03日 ⁄ 综合 ⁄ 共 524字 ⁄ 字号 评论关闭

① 自动创建索引:当创建
unique
pk
约束时,索引自动创建。

② 手动创建索引:

create index emp_ename_index on emp(ename);

哪些列适合建索引

经常出现在where子句的列。

经常用于表连接的列。

该列包含许多null值。

表很大,查询的结果集却很小。

pk列和unique列。

fk列。


经常需要排序和分组的列。

索引的存在意义在于提高查询效率。

最后注意:索引不是万能的。

哪些列不适合建索引

表很小。

列很少出现在where子句。

查询的结果集很大。

该列经常被更新。

哪些写法会导致索引用不了

① 函数导致索引用不了

where upper(first_name)=' tom ;

② 表达式导致索引用不了

where sal*12=18000 ;

③ 部分隐式数据类型导致索引用不了

where c1=2( c1为varchar2类型 ) ;

④ like

where first_name like 'CA%' ;

⑤ 否定形式导致索引用不了

where first_name<>' tom ' ;

where sal not between 1000 and 2000 ;

where deptno not in(10,20,30) ;

⑥ is null导致索引用不了

where comm is null ;




抱歉!评论已关闭.