SQL Server,Oracle,DB2索引建立语句的对比

SQL Server,Oracle,DB2索引建立语句的对比

摘自:http://database.51cto.com/art/201108/284540.htm

 

我们知道,索引是用于加速数据库查询的数据库对象。原理就是减少查询的IO操作,从而达到加速的目的。本文我们主要对SQL Server,Oracle,DB2上的索引建立语句进行了总结,接下来就让我们一起来了解一下这部分内容。

索引的种类:

聚集索引:根据数据行的键值在表或视图中排序和存储这些数据行.

非聚集索引:具有独立于数据行的结构.

唯一索引:确保索引键不包含重复的值.

在SQL SERVER上建立的索引:

Create (NONCLUSTERED ) index ind_emp on emp(empno); 默认的就是建立非聚集索引。

exec sp_helpindex emp; 用于查看建立的索引,查询会自己使用可以用到的索引。

Create index ind_emp1 on emp(empno,ename); 可以在多个列上建立复合索引。

唯一非聚集索引:

Create unique index ind_sal on emp(sal);

重新生成索引:

Alter index ind_sal on emp rebuild;

Drop index ind_emp on emp; 删除索引。

Create CLUSTERED  index ind_emp on emp(empno); 建立聚集索引。

Create index ind_emp on emp(empno,ename);

注:相同列上可以多次索引。

唯一聚集索引:

Create unique clustered index ind_sal on f_emp(sal);

在DB2上建立索引:

非唯一索引:create index ind_empno on emp(empno);

Describe indexes for table emp; 查看所建立的索引。

唯一索引:create unique index ind_empno on emp(empno);

纯索引是DB2上的一种特殊的索引,(相当于ORACLE上的索引组织表):相对与一般索引。如下方式表中有俩个字段,其中字段1是唯一主键,字段2为数据,实际的查询中经常是select empno,ename from emp where empno=1122;CREATE UNIQUE INDEX IDX_ENAME ON emp (empno) INCLUDE(eNAME)。上述的语句的意思就是在empno上创建唯一索引,选择包含ename的数据,这些附加的数据将与键存储到一起。

Drop index ind_emp;

Create  index ind_emp on emp(empno) cluster;

Create index ind_emp on emp(empno,ename);

唯一聚集索引:

drop index ind_emp;-- 一个表上只能有一个聚集索引。

Create unique  index ind_sal on u_emp(sal) cluster;  建立聚集索引。

在ORACLE上建立索引:

SQL>  create index ind1 on emp(mgr); BTree索引。

SQL> create index ind2 on emp(deptno) reverse; 反向索引。

SQL> create index ind3 on emp(hiredate desc); 降序索引。

SQL> create bitmap index ind4 on emp(sal); 位图索引。

SQL>  create index ind5 on emp upper(job); 函数索引。

关于SQL Server,Oracle,DB2上的索引建立语句的总结就介绍到这里了,希望本次的介绍能够对您有所收获!

猜你喜欢

转载自lbwahoo.iteye.com/blog/1978541
今日推荐