-- create table
CREATE TABLE dbo.Tests
(
Id BIGINT NOT NULL IDENTITY,
String NVARCHAR(100),
StringReversed AS REVERSE(String),
CONSTRAINT PK_Tests PRIMARY KEY (Id),
)
CREATE NONCLUSTERED INDEX IX1 ON dbo.Tests(String)
CREATE NONCLUSTERED INDEX IX2 ON dbo.Tests(StringReversed)
-- populate table with 100k random strings (for testing)
DECLARE @I INT = 100000
WHILE @I > 0
BEGIN
INSERT INTO Tests(String)
SELECT CONVERT(varchar(36), NEWID())
SET @I = @I - 1
END
-- how do i do a LIKE '%STRING%' search which uses the index?
SELECT String, StringReversed FROM Tests WHERE String LIKE '%0A7EB%'
SELECT String, StringReversed FROM Tests
WHERE String LIKE '0A7EB%' OR StringReversed LIKE 'BE7A0%'
Can you help me with this? I am trying to implement a full-text-search alternative to be able to do a LIKE '%STRING%' WHERE clause.
I'm stuck not quite sure if this is even possible to implement? Let's just assume that FULL TEXT SEARCH is not possible, and I need to use index.
This is a prod issue and we need to do a LIKE '%search%' in the string column. I just read here: SQL Server: Index columns used in like? that we can do a reverse?
Hope you can help me, thanks a lot.