那些臭名昭著的sql
- 两个或多个表关联,没写where条件,大量的笛卡尔值,严重时会导致数据库有问题。
select * from a, b left join c on b.id = c.id left join d on c.id = d.id
- 多表关联查询,where条件使用各种函数,导致索引无效。数据量如果打起来以后会导致查询像蜗牛一样。
select trim(d.circuitid) as circuitid, trim(d.Code) as Code, trim(d.Oldname) as Oldname, trim(d.Circuittype) as Circuittype, trim(d.Status) as Status, trim(d.customerid) as acustomerid, trim(d.alinkman) as alinkman, trim(d.zlinkman) as zlinkman, trim(d.alinkmantel) as alinkmantel, trim(d.zlinkmantel) as zlinkmantel, trim(d.busi_no) as busi_no, trim(d.service_serial) as service_serial, trim(a.region_ID) as regionid , 2 as SORTID from test1 a,test2 b,test3 c,test4 d where trim(a.room_id)=trim(b.roomID) and trim(b.neid)=trim(c.neid) and (trim(c.portid)=trim(d.aendname) or trim(c.portid)=trim(d.zendname))
扫描公众号,关注更多信息
---------------------------------------------------------------------------------我是分割线--------------------------------------------------------------------------to be a better me, talk is cheap show me the code
版权所有,转载请注明原文链接。
文中有不妥或者错误的地方还望指出,以免误人子弟。如果觉得本文对你有所帮助不妨【推荐】一下!如果你有更好的建议,可以给我留言讨论,共同进步!
再次感谢您耐心的读完本篇文章。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------