首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求帮忙优化SQL,该怎么处理

2012-01-19 
求帮忙优化SQLselectdistincta.file_nameasbqyname,a.unique_idasmenuidfrombriocat2a,bqy_rolerightb,por

求帮忙优化SQL
select   distinct   a.file_name   as   bqyname,a.unique_id   as   menuid   from   briocat2   a,bqy_roleright   b,portal_userroles   c   where  

c.userid=@userId   and   b.role_id=c.roleid   and   a.unique_id=b.resource_id   and   a.parent_id   is   not   null   and   a.unique_id   not   in   (select   aa.menuid   from  

portal_indivdetail   aa,briocat2   bb   where   aa.userid=@userId   and   aa.menuid=bb.unique_id   and   aa.tabid=2   and   bb.parent_id   is   not   null)

这个SQL中,各个表中记录都很少,最多一个表不过3000条左右,因为数据少所有都没有建索引。但是在这个查询中速度却慢得奇怪,竟然需要30~40秒才能查出来。请问大家有何解决办法?谢谢。

[解决办法]
坐关联,建索引,尽量不用not语句!

热点排行