SQL Server,Oracle,DB2索引建立语句的对比
2016-03-21 10:09
555 查看
原文引至:http://jvortex.blog.163.com/blog/static/16961890020122141010878/
我们知道,索引是用于加速数据库查询的数据库对象。原理就是减少查询的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上的索引建立语句的总结就介绍到这里了,希望本次的介绍能够对您有所收获!
我们知道,索引是用于加速数据库查询的数据库对象。原理就是减少查询的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上的索引建立语句的总结就介绍到这里了,希望本次的介绍能够对您有所收获!
相关文章推荐
- MySQL,Oracle,SQL Server——选取前10条——语法差异
- Oracle 11g 学习2——SQLPlus命令
- 创建Oracle数据库
- oracle 表空间(数据文件)满了后 修改表空间大小
- Oracle 函数
- oracle user account locked
- Oracle导出导入数据库的方式
- oracle trunc()函数的使用
- Oracle 11g服务器监听配置
- oracle rman 数据备份
- oracle11R2 log_archive_format
- ORACLE之搭建DG(COPY数据文件方式)
- Oracle的闪回操作
- 一、Oracle学习总结和SQL记录
- oracle命令创建表空间和用户以及权限授权
- Oracle以SQL方式导出导入(转移)数据
- oracle、sql server、mysql分页
- oracle 12cr1 sqlldr errors参数差异
- Oracle Total Recall Tips
- Oracle SQL 性能优化粗略总结