1. 程式人生 > >[置頂] 解決“提示錯誤: 無法對 表或索引檢視'T_shili' 使用 CONTAINS 或 FREETEXT 謂詞,因為它未編制全文索引。 ”

[置頂] 解決“提示錯誤: 無法對 表或索引檢視'T_shili' 使用 CONTAINS 或 FREETEXT 謂詞,因為它未編制全文索引。 ”

依據錯誤提示解決問題。

create table T_shili(id int not null, name varchar(10))
insert   T_shili
select 1,'lee' union all
select 2,'zhang' union all
select 3,'wang' 
----首先建立一個唯一索引,以便全文索引利用*/
create unique clustered  index unique_index_id on T_shili(id)
----建立全文目錄*/
create FULLTEXT CATALOG FT AS DEFAULT
----建立全文索引*/
create FULLTEXT INDEX ON T_shili(NAME) key index unique_index_id  ON  FT

進行測試:

select * from T_shili
where contains(name,'e')

結果:

理論上可查出資料,為什麼沒有呢?

這是因為“資訊: 全文搜尋條件中包含干擾詞。”

這是contains查詢的一個缺點。

我一般用模糊查詢來代替contains查詢。

例如上個例項。

select * from T_shili
where name not like '%e'

結果: