- 时间:2020-08-06 23:56 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:sqlserver 中charindex/patindex/like 的比较
[b]一、测试环境:[/b]
1。数据库:Sql Server 2008
2。测试表:15000记录,char类型主键,无其他索引
3。测试字段:ntext 类型,最大数据长度12000
[b]二、测试语句:[/b]
1。select * from ProductTemp where ProductDesc like '2.168.70.236%'
2。select * from ProductTemp where charindex('192.168.70.236',ProductDesc)>0
3。select * from ProductTemp where patindex('2.168.70.236%',ProductDesc)>0
[b]三、测试结果:[/b]
1。效率测试结果: charindex > like > patindex ,效率差大概20%
2。适用性测试结果:
1)charindex对于检索结果最大位移有要求,经测试,Sql2008中的ntext字段,位移不能超过3987,否则返回0;
2)patindex 和 like 无位移限制;
3)patindex 支持匹配表达式,可以应用正则;
4)like可以用'%oldstring%'进行模糊匹配;
5)charindex只能匹配固定字符串