sqlserver 中charindex/patindex/like 的比较,大家可以看下根据需要自行选择。
一、测试环境: 1。数据库:Sql Server 2008
2。测试表:15000记录,char类型主键,无其他索引
3。测试字段:ntext 类型,最大数据长度12000
二、测试语句: 1。select * from ProductTemp where ProductDesc like '%192.168.70.236%'
2。select * from ProductTemp where charindex('192.168.70.236',ProductDesc)>0
3。select * from ProductTemp where patindex('%192.168.70.236%',ProductDesc)>0
三、测试结果: 1。效率测试结果: charindex > like > patindex ,效率差大概20%
2。适用性测试结果:
1)charindex对于检索结果最大位移有要求,经测试,Sql2008中的ntext字段,位移不能超过3987,否则返回0;
2)patindex 和 like 无位移限制;
3)patindex 支持匹配表达式,可以应用正则;
4)like可以用'%oldstring%'进行模糊匹配;
5)charindex只能匹配固定字符串
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn