| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1408 人关注过本帖
标题:如何更快的查询数据
取消只看楼主 加入收藏
jxawgyl
Rank: 1
等 级:新手上路
帖 子:208
专家分:0
注 册:2007-10-16
结帖率:100%
收藏
 问题点数:0 回复次数:3 
如何更快的查询数据
如何更快的查询数据
现有四张表RecipeList,Outpatient ,Recipe,MedicineInspect ,查询每张表只要0.1秒时间,现建张视图表查询却要5分多,其如下:SELECT dbo.Outpatient.PatCode, dbo.Outpatient.PatName, dbo.Outpatient.Age,
      dbo.Outpatient.Sex, dbo.Outpatient.PatKindName, dbo.Outpatient.MedInsName,
      dbo.Outpatient.OffCode, dbo.MedicineInspect.MedName,
      dbo.MedicineInspect.MedSpec, dbo.MedicineInspect.StoreUnit,
      dbo.MedicineInspect.RoomUnit, dbo.MedicineInspect.ConvertUnit,
      dbo.MedicineInspect.MedSortCode, dbo.MedicineInspect.FinSortCode,
      dbo.MedicineInspect.PhaSortCode, dbo.MedicineInspect.MedModelCode,
      dbo.MedicineInspect.FivePen, dbo.MedicineInspect.Spell,
      dbo.MedicineInspect.Grade, dbo.MedicineInspect.MedSortName,
      dbo.MedicineInspect.FinSortName, dbo.MedicineInspect.PhaSortName,
      dbo.MedicineInspect.MedModelName, dbo.MedicineInspect.TendSortName,
      dbo.MedicineInspect.NongYi, dbo.MedicineInspect.ExecuteOffice,
      dbo.MedicineInspect.Sort, dbo.RecipeList.RecCode, dbo.RecipeList.Flow,
      dbo.RecipeList.MedCode, dbo.RecipeList.Number, dbo.RecipeList.RoomPrice,
      dbo.RecipeList.SendOpe, dbo.RecipeList.Sendtime, dbo.RecipeList.BackDrugOpe,
      dbo.RecipeList.BackDrugTime, dbo.RecipeList.BackChaOpe,
      dbo.RecipeList.ChargeOpe, dbo.RecipeList.CancelOpe, dbo.RecipeList.RoomCode,
      dbo.RecipeList.AddTime, dbo.RecipeList.DocCode, dbo.RecipeList.DocName,
      dbo.RecipeList.CancelSign, dbo.RecipeList.PreBackNum, '西药房' AS OffName,
      dbo.RecipeList.InsSign, dbo.RecipeList.AllMoney, dbo.RecipeList.SelfMoney,
      dbo.Operator.OpeName, dbo.Outpatient.OpeCode, dbo.Office.OffName AS OffName1,
      dbo.RecipeList.CheckSign, dbo.Recipe.YBRecCode
FROM dbo.RecipeList INNER JOIN
      dbo.Outpatient INNER JOIN
      dbo.Recipe ON dbo.Outpatient.PatCode = dbo.Recipe.PatCode ON
      dbo.RecipeList.RecCode = dbo.Recipe.RecCode INNER JOIN
      dbo.MedicineInspect ON
      dbo.RecipeList.MedCode = dbo.MedicineInspect.MedCode INNER JOIN
      dbo.Operator ON dbo.Outpatient.OpeCode = dbo.Operator.OpeCode INNER JOIN
      dbo.Office ON dbo.Outpatient.OffCode = dbo.Office.OffCode

请教各位应如何修改?
搜索更多相关主题的帖子: 数据 查询 
2010-09-30 08:43
jxawgyl
Rank: 1
等 级:新手上路
帖 子:208
专家分:0
注 册:2007-10-16
收藏
得分:0 
为何用select *  from dbo.RecipeView    where addtime>'2010-01-01'时需要46秒,而select *  from dbo.RecipeView 却要5分多.而所有表中只有大于'2010-01-01'时间的数据.用不用where addtime>'2010-01-01'其查询结果应是相同的,查询时间却有长短,请教?
2010-09-30 09:21
jxawgyl
Rank: 1
等 级:新手上路
帖 子:208
专家分:0
注 册:2007-10-16
收藏
得分:0 
原本表中只有大于'2010-01-01'时间的数据加,加不加应一样,加外问一下,如何修改视图表,使其查询时间缩短?
2010-09-30 09:58
jxawgyl
Rank: 1
等 级:新手上路
帖 子:208
专家分:0
注 册:2007-10-16
收藏
得分:0 
仔细看了一下,你竟然用了5个“inner join”这个导致速度下降是必然的!(Inner Join本来就快不了)
请教8楼的楼主,应如何才能修改了?
2010-10-12 09:22
快速回复:如何更快的查询数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016245 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved