由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - MS SQL = or like?
相关主题
Merge table with one single query?存取中文问题in MSSql 7.0
刚提升为数据库部门经理,寻同道支持和交流!请教一个数据库设计的问题
help needMSSQL Performance Counters
ADO & DAO &SQL...Help...被MARGINALIZED了
MS Access QuestionSQL Server下,如何有效管理VIEW?
Re: How to change Default SQL String Buffer Size(1K) for ODBC DriverHow to concatenate NULL value with a string in SQL Server?
about mixed case stringHow to write this query
[转载] problem with chinese character包子题 (1st answer 100新币)
相关话题的讨论汇总
话题: like话题: ms话题: sql话题: where话题: string
进入Database版参与讨论
1 (共1页)
c**t
发帖数: 2744
1
MS SQL:
where field = 'string'
or
where field like 'string'?
Both work, which one is right?
c**t
发帖数: 2744
2
It seems "=" is faster. :-)

【在 c**t 的大作中提到】
: MS SQL:
: where field = 'string'
: or
: where field like 'string'?
: Both work, which one is right?

f*****g
发帖数: 15860
3
if u know the exact string you're looking ofr, why bother to use LIKE?

【在 c**t 的大作中提到】
: It seems "=" is faster. :-)
c**t
发帖数: 2744
4
One said LIKE is standard;

【在 f*****g 的大作中提到】
: if u know the exact string you're looking ofr, why bother to use LIKE?
n********a
发帖数: 68
5
It matters not which one performs better or which one is standard.
The only thing that matters is correctness.
If the question you query is trying to answer requires LIKE,
by all means, use LIKE, and forget about the performance.
Performance will only come to play when = or like will provide
the SAME CORRECT answer.
As fryking mentioned, if you know the exact string, use =.
LIKE will be the wrong answer.
It seems unlikely to me where = or like will be equivalent
and provide the same correct answ

【在 c**t 的大作中提到】
: One said LIKE is standard;
c**t
发帖数: 2744
6
1) select * from TBL
where email = 'w*****[email protected]'
2) select * from TBL
where like 'w*****[email protected]'
Time: 1) 00:00:01 2) 00:00:04
My observation is = faster for this case.

【在 n********a 的大作中提到】
: It matters not which one performs better or which one is standard.
: The only thing that matters is correctness.
: If the question you query is trying to answer requires LIKE,
: by all means, use LIKE, and forget about the performance.
: Performance will only come to play when = or like will provide
: the SAME CORRECT answer.
: As fryking mentioned, if you know the exact string, use =.
: LIKE will be the wrong answer.
: It seems unlikely to me where = or like will be equivalent
: and provide the same correct answ

a*******t
发帖数: 891
7
=
use like for '%string%' search

【在 c**t 的大作中提到】
: MS SQL:
: where field = 'string'
: or
: where field like 'string'?
: Both work, which one is right?

s******s
发帖数: 508
8
To make your comparison meaningful, you need to give the table structure and
the index(es) on it.
I agree that generally = is more efficient than like since like uses range
scan while = is exact match.

【在 c**t 的大作中提到】
: 1) select * from TBL
: where email = 'w*****[email protected]'
: 2) select * from TBL
: where like 'w*****[email protected]'
: Time: 1) 00:00:01 2) 00:00:04
: My observation is = faster for this case.

c**t
发帖数: 2744
9
The TBL is a general one, no index(es) built on it. If the compiler is smart
enought, will it convert "email like 'whatever@..'" to "email = 'whatever@..'"?
For the time I gave which is meaningless without knowing the table strtucture
and index(es), you are damn right. :-) But I just tried to show the difference

【在 s******s 的大作中提到】
: To make your comparison meaningful, you need to give the table structure and
: the index(es) on it.
: I agree that generally = is more efficient than like since like uses range
: scan while = is exact match.

1 (共1页)
进入Database版参与讨论
相关主题
包子题 (1st answer 100新币)MS Access Question
问一个sql查询语句的问题Re: How to change Default SQL String Buffer Size(1K) for ODBC Driver
抱怨一下 数据库 里头的一些不严谨。about mixed case string
Re: [转载] JDBC用完了oracle的large pool (memor[转载] problem with chinese character
Merge table with one single query?存取中文问题in MSSql 7.0
刚提升为数据库部门经理,寻同道支持和交流!请教一个数据库设计的问题
help needMSSQL Performance Counters
ADO & DAO &SQL...Help...被MARGINALIZED了
相关话题的讨论汇总
话题: like话题: ms话题: sql话题: where话题: string