在SQL Server上喜欢vs包含 [英] LIKE vs CONTAINS on SQL Server

查看:79
本文介绍了在SQL Server上喜欢vs包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下哪个查询更快(喜欢vs包含)?

Which one of the following queries is faster (LIKE vs CONTAINS)?

SELECT * FROM table WHERE Column LIKE '%test%';

SELECT * FROM table WHERE Contains(Column, "test");


推荐答案

第二个(假设您表示 内容 ,并实际上将其放入有效查询中)更快,因为它可以使用 some 形式的索引(在本例中为全文索引)。当然,仅当列位于全文索引中时,这种查询形式才可用。

The second (assuming you means CONTAINS, and actually put it in a valid query) should be faster, because it can use some form of index (in this case, a full text index). Of course, this form of query is only available if the column is in a full text index. If it isn't, then only the first form is available.

使用LIKE的第一个查询将无法使用索引,因为它以通配符开头,因此始终需要进行全表扫描。

The first query, using LIKE, will be unable to use an index, since it starts with a wildcard, so will always require a full table scan.

内容

The CONTAINS query should be:

SELECT * FROM table WHERE CONTAINS(Column, 'test');

这篇关于在SQL Server上喜欢vs包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆