当前位置: 代码迷 >> Sql Server >> 这条查询的SQL语句应该如何优化才能速度更快?求高手解答
  详细解决方案

这条查询的SQL语句应该如何优化才能速度更快?求高手解答

热度:58   发布时间:2016-04-27 20:00:31.0
这条查询的SQL语句应该怎么优化才能速度更快?求高手解答!
"select   FieldContent   from   QBS_SHOPInfo_ntext   where   shopID= "&shopID& "   and   (FieldName= 'shopIntro '   or   FieldName= 'ServiceSDD '   or   FieldName= 'ZiZhi '   or   FieldName= 'BuildCharacteristic '   or   FieldName= 'ServicePrice '   or   FieldName= 'DesignSDD '   or   FieldName= 'zuixincuxiao '   or   FieldName= 'ServiceProcess ') "

------解决方案--------------------
加索引
------解决方案--------------------
shopID,FieldName加索引试试
------解决方案--------------------
不要這樣寫吧


"select FieldContent from QBS_SHOPInfo_ntext where shopID= "&shopID& " and (FieldName in( 'shopIntro ', 'ServiceSDD ', 'ZiZhi ' , 'BuildCharacteristic ' , 'ServicePrice ', 'DesignSDD ' , 'zuixincuxiao ', 'ServiceProcess ')) "

------解决方案--------------------
對shopID加索引
------解决方案--------------------
create NONCLUSTERED index index_name
on tablename
(shopID,FieldName)
------解决方案--------------------
不要這樣寫吧


"select FieldContent from QBS_SHOPInfo_ntext where shopID= "&shopID& " and (FieldName in( 'shopIntro ', 'ServiceSDD ', 'ZiZhi ' , 'BuildCharacteristic ' , 'ServicePrice ', 'DesignSDD ' , 'zuixincuxiao ', 'ServiceProcess ')) "
___________________________________________________________________________________

这样与原来的那样执行效率一样
------解决方案--------------------
select FieldContent from QBS_SHOPInfo_ntext a inner join
(select 'shopIntro ' FieldName
union all
select 'ServiceSDD '
....
union all
select 'ServiceProcess '
) as b on a.FieldName=b.FieldName where shopID= "&shopID& "
------解决方案--------------------
没什么问题加索引
  相关解决方案