读书人

这条查询的SQL语句应该如何优化才能速

发布时间: 2012-01-09 21:05:42 作者: rapoo

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

读书人网 >SQL Server

热点推荐