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

来源:互联网 发布:网络恶意诽谤 编辑:程序博客网 时间:2024/05/16 05:56

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


② 手动创建索引:

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 ;