SQL SERVER查询优化

在数据库查询过程中经常会遇到语句查询慢,执行效率低的情况,以后归纳总结如下:

1. 查询存在A表不存在B表的语句

select * from a where (select count(1) from b where b.id=a.id)=0

原来效率低的查询为:

select * from a where a.id not in (select id from b )

注意:如果在查询的时候B表中的值有null的时候,通过in 和not in 的查询最后会没有结果返回。所以此种方法一般大家都不推荐。

另一种改进查询方法为 :

select * from a left join b on a.id=b.id where b.id is null

2.Oracle中快速查看表的行数:

select t.table_name,t.num_rows from user_tables t

3.SQL SERVER中快速查看表的行数:

select schema_name(t.schema_id) as [Schema], t.name as TableName,i.rows as [RowCount]
from sys.tables as t, sysindexes as i
where t.object_id = i.id and i.indid <=1
AND t.name = '表名'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值