sql语句突然执行要很长时间

yuanhao0407 2017-07-06 11:27:52
select t3.CustomerName,t5.TypeName,t4.SheetColor,t4.SheetFab,t4.SheetFabD, t4.Thickness,t4.SheetNorm,t4.Style,
t6.Name as UnitName,t2.OrderDate,t2.BillNO,t1.Quantity as NQuantity,t1.Price,t1.Remarks,
t1.Quantity-ISNULL((select SUM(t7.Number) from tbInStorageDetail as t7 left join tbInStorage as t8 on t7.InStorageID=t8.ID
where t7.RelatedOrderNO=t1.BillNO and t7.GoodsID=t4.ID and t8.CheckStatus=2),0) as Quantity
from tbSaleQuotationDetail as t1
left join tbSaleQuotationList as t2 on t1.BillNO=t2.BillNO
left join tbCustomer as t3 on t3.CustomerID=t2.CustomerID
left join tbProduct as t4 on t4.ProductID=t1.ProductNO
left join tbType as t5 on t5.ID=t4.Type
left join tbUnit as t6 on t6.ID=t4.Unit
where (t1.EndStatus != 1 or t1.EndStatus = 2 ) and t2.CheckStatus=2 and
t1.Quantity-ISNULL((select SUM(t7.Number) from tbInStorageDetail as t7 left join tbInStorage as t8 on t7.InStorageID=t8.ID
where t7.RelatedOrderNO=t1.BillNO and t7.GoodsID=t4.ID and t8.CheckStatus=2),0) > 0
...全文
548 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanhao0407 2017-07-06
  • 打赏
  • 举报
回复
之前都很快的,现在这么简单的sql语句要25秒。。。数据量也不大
yuanhao0407 2017-07-06
  • 打赏
  • 举报
回复
就是数据库的问题,可能之前给服务器上安装的SQL server 2012 有问题,重新换了数据库就好了。
xdashewan 2017-07-06
  • 打赏
  • 举报
回复
引用 4 楼 github_36859217 的回复:
这几个表都没有建索引
那首先得把索引建了,08上面有索引没
OwenZeng_DBA 2017-07-06
  • 打赏
  • 举报
回复
引用 6 楼 github_36859217 的回复:
最后排除了其它原因,就剩下是数据库的问题了,这条语句在SQLserver2008上面执行很快,在SQLserver2012上执行很慢
你早就应该吧这个背景写出来
yuanhao0407 2017-07-06
  • 打赏
  • 举报
回复
最后排除了其它原因,就剩下是数据库的问题了,这条语句在SQLserver2008上面执行很快,在SQLserver2012上执行很慢
yuanhao0407 2017-07-06
  • 打赏
  • 举报
回复
引用 3 楼 z10843087 的回复:
这个语句并不简单。很多大表的join。如果以前很快,现在很慢,可以检查下是做了什么修改。
就这几天的时间,并没有做什么修改
yuanhao0407 2017-07-06
  • 打赏
  • 举报
回复
引用 2 楼 xdashewan 的回复:
索引时间很长了吗?可以试试重新建下索引
这几个表都没有建索引
OwenZeng_DBA 2017-07-06
  • 打赏
  • 举报
回复
这个语句并不简单。很多大表的join。如果以前很快,现在很慢,可以检查下是做了什么修改。
xdashewan 2017-07-06
  • 打赏
  • 举报
回复
索引时间很长了吗?可以试试重新建下索引

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧