您的位置:首页 > 博客中心 > 数据库 >

SQL之性能优化

时间:2022-03-14 17:17

select empno,eName,salary from employee where salary>1000 and salary<3000

select empno,eName,salary from employee where salary<3000 and salary>1000

select stuid,curid ,curName,result from t_result r,t_curriculum t where t.curid=t.curid --应该将表与表联合放在前面 and t.stuid='123'

select empno,eName from employee where eptno=10 or eptno=15

select empno,eName from employee where eptno in(10,15)--相当于创建了索引

select empno,eName,salary from employee where salary<3000 or salary>3000

select s.stuid,s.stuName,s.age,s.sex from t_student s where exists (select * from t_result t where s.stuid=t.stuid and t.curid='t105')

select s.stuid,s.stuName,s.age,s.sex from t_student s where s.stuid in (select * from t_result t where s.stuid=t.stuid and t.curid='t105')

select stuid,stuName,age from t_student where stuid like '%100%'

select stuid,stuName,age from t_student where stuid like 's100%'


注意:在实际应用中也许必须要实现第一种查询方法才能满足,这里只是让大家知道这样会降低查询的效率。

 

8.避免使用HAVING子句


HAVING子句是用来对分组后的结果进行过滤,限制分组后的查询结果。在使用时一般需要执行排序,统计等功能,这就会消耗SQL额外工作,因此应该避免使用这些操作

使用存储过程

存储过程是经过编译的,永久保存在数据中的一组SQL语句,使用存储过程执行效率要比SQL语句执行效率高


小结:以上只是一部分SQL语句来改善数据库性能的方法,后面还会有相关的文章,敬请期待。

 

 

SQL之性能优化,布布扣,bubuko.com

热门排行

今日推荐

热门手游