SqlServer和Oracle中一些常用的sql语句9-SQL优化

2014-11-24 15:32:51 · 作者: · 浏览: 0
SqlServer和Oracle中一些常用的sql语句9-SQL优化

SqlServer和Oracle中一些常用的sql语句8-触发器和事务
http://www.2cto.com/database/201306/222475. html
[sql]
--SQL查询优化 尽量避免使用or,not,distinct运算符,简化连接条件
/*Or运算符*/
use db_business
go
select * from 仓库 where 城市='北京' or 城市='青岛' --包含or运算符 sql将不使用索引,影响速度
/*In运算符*/
use db_business
go
select * from 仓库 where 城市 in('北京' ,'青岛') --有效提高运算效率
/*not运算符*/
use db_business
go
select * from 仓库 where 城市 not in('北京')
/*比较运算符*/
use db_business
go
select * from 仓库 where 城市!='北京' --有效提高运算效率
/*使用distinct关键字*/
use db_business
go
select distinct * from 仓库 where 面积>900
/*不使用distinct关键字*/
use db_business
go
select * from 仓库 where 面积>900 --无必要,不使用distinct可有效提高运算效率
/*使用And运算符*/
use db_business
go
select * from 职工 where 工资>=1500 and 工资<=1800
/*使用Between简化联接条件*/
use db_business
go
select * from 职工 where 工资 between 1500 and 1800 --between可有效提高运算效率