日期:2014-05-19  浏览次数:20570 次

这条查询的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& "
------解决方案--------------------
没什么问题加索引