avatar
MS SQL = or like?# Database - 数据库
c*t
1
MS SQL:
where field = 'string'
or
where field like 'string'?
Both work, which one is right?
avatar
c*t
2
It seems "=" is faster. :-)

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

avatar
f*g
3
if u know the exact string you're looking ofr, why bother to use LIKE?

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

【在 f*****g 的大作中提到】
: if u know the exact string you're looking ofr, why bother to use LIKE?
avatar
n*a
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;
avatar
c*t
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

avatar
a*t
7
=
use like for '%string%' search

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

avatar
s*s
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.

avatar
c*t
9
The TBL is a general one, no index(es) built on it. If the compiler is smart
enought, will it convert "email like '[email protected]'" to "email = '[email protected]'"?
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。