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只能匹配固定字符串

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...