使用'='或LIKE来比较SQL中的字符串? [英] Use '=' or LIKE to compare strings in SQL?
本文介绍了使用'='或LIKE来比较SQL中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有(几乎是宗教的)讨论,如果你应该使用LIKE或'='来比较SQL语句中的字符串。
There's the (almost religious) discussion, if you should use LIKE or '=' to compare strings in SQL statements.
- 有理由使用LIKE吗?
- 是否有理由使用=?
- 可读性?
提前感谢!
推荐答案
要查看性能差异,请尝试:
To see the performance difference, try this:
SELECT count(*)
FROM master..sysobjects as A
JOIN tempdb..sysobjects as B
on A.name = B.name
SELECT count(*)
FROM master..sysobjects as A
JOIN tempdb..sysobjects as B
on A.name LIKE B.name
使用=来比较字符串要快得多。
Comparing strings with '=' is much faster.
这篇关于使用'='或LIKE来比较SQL中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文