数据量大,求各位大虾门帮忙提个优化方案!SELECT TOP 10 ID,Title
FROM T_Info
WHERE (KeyWord LIKE '%人%') OR
      (Title LIKE '%人%') OR
      (KeyWord LIKE '%我%') OR
      (Title LIKE '%我%') OR
      (KeyWord LIKE '%知道%') OR
      (Title LIKE '%知道%')
ORDER BY ID DESC

解决方案 »

  1.   

    like  '%知道%'索引无效换全文检索+contains函数
      

  2.   

    一个完整的例子:前提条件:安装好全文检索服务,并启动--建立表,插入数据,建立全文索引if ( (select count(*) from sysobjects where name = 'testft' and type = 'U') > 0)
    drop table testftcreate table testft(
     id int identity(1,1) constraint pk_testft primary key,
     title nvarchar(500),
     content nvarchar(2000)
    )insert into testft values ('This is title', 'this is content')
    insert into testft values ('My name is sqlserver', 'Hello, everyone')
    insert into testft values ('这里是标题','这里是内容')
    insert into testft values ('江西', '南昌')
    insert into testft values ('湖南', '长沙')
    insert into testft values ('河南', '郑州')execute sp_fulltext_database 'enable'execute sp_fulltext_catalog 'ft_testft', 'CREATE'execute sp_fulltext_table 'testft', 'CREATE', 'ft_testft', 'pk_testft'execute sp_fulltext_column 'testft', 'title', 'ADD'
    execute sp_fulltext_column 'testft', 'content', 'ADD'execute sp_fulltext_table 'testft', 'ACTIVATE'execute sp_fulltext_catalog 'ft_testft', 'START_FULL'--执行完以上语句,再执行以下语句
    --查询:declare @keyword varchar(50)
    set @keyword = '南'
    select * from testft
    select * from testft where contains(*, @keyword)--引用自  netcoder(朱二)
      

  3.   

    --配置好全文索引后,可以用如下方式查询.
    SELECT *
    FROM 表
    WHERE CONTAINS (KeyWord, '("人" or "我" or "知道") AND NOT "适合"')