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.
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');
Answer from Damien_The_Unbeliever on Stack OverflowThe 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.
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');
Having run both queries on a SQL Server 2012 instance, I can confirm the first query was fastest in my case.
The query with the LIKE keyword showed a clustered index scan.
The CONTAINS also had a clustered index scan with additional operators for the full text match and a merge join.
I have been doing some tinkering with full text indexes in SQL Server 2019. I've found that I am getting different results when compared to a 'like' statement.
Here is my example code. I am using StackOverflow2010 sample database.
-- create full text catalog and index CREATE FULLTEXT CATALOG fulltextCatalog AS DEFAULT; go CREATE FULLTEXT INDEX ON dbo.Posts(Tags) KEY INDEX PK_Posts__Id WITH STOPLIST = SYSTEM; go -- wait a while after running this, then run the selects select count(*) as ContainsResults from Posts where contains(Tags, 'sql') select count (*) as LikeResults from Posts as p where Tags like '%sql%'
Results:
ContainsResults 59620 LikeResults 94039
Execution Plan:
This data looks like this:
select top 10 Tags from Posts where Tags like '%sql%' Tags <mysql><database><binary-data><data-storage> <mysql><database><triggers> <sql><sql-server><datatable><rdbms> <php><sql><database><flat-file> <c#><sql><vb.net><ascii><hex> <sql><asp.net><xml><sitemap> <mysql><sql-server><csv><sql-server-2005><bcp> <sql-server><database><svn><version-control> <sql-server><migration> <mysql><sql-server><sql-server-2005>