测试环境sqlserver2005
ITPUB个人空间:uQH,EV8r:x
YaB2d
X0drop table test
q
wV1YU$pi0go
ITPUB个人空间"V6LSqV9X,JaSITPUB个人空间~pN!WZ
W%VCREATE TABLE test
ITPUB个人空间J$dq[
}aucp.v(
-sM-W*j:pKiK0 id int NOT NULL,
V j|+N1aHs8W0 name varchar(50) NOT NULL,
Qf gv!a0 descr text not NULL
0ju1]
O3A0);
)r[WK8Q0~s {2y:bC0go
ITPUB个人空间vv$eZ8B.Z'n-V3M]Ddelete from test;
sK]!f+|_%iQ0insert into test values(0,'epfoxfire ep','foxfoxmix mix');
ITPUB个人空间.k1O}T9{H3GZuinsert into test values(1,'震荡 夺取 震荡夺取','bb b');
ITPUB个人空间8gi Z0_A\0jinsert into test values(2,'ep 天花乱坠','foxfoxmix fox');
3X]"v3z%Y}*@ P}(N0go
wM#{*P
p0E.P7Q+_2}Vi5x0create unique index idx_name on test(name);
"J&V9X:JUI0ITPUB个人空间/~Lrii)Icreate unique index idx_id on test(id);
4TFM.ZVT-w/PW*kf0go
ITPUB个人空间O1B*Ca$PITPUB个人空间,aO+bCIC}+aosAg9aQ;Tb(d6f0--检查数据库pubs是否支持全文索引,如果不支持
ITPUB个人空间{H0y8`6X@9o9H--则使用sp_fulltext_database 打开该功能
is0owL
C\Ib0if(select databaseproperty('test','isfulltextenabled'))=0
ITPUB个人空间bt7s9z)I m.d#P_execute sp_fulltext_database 'enable'
ITPUB个人空间&`)s ?*Z)_~i A!Ui%Y.iJ%K
z+H0--建立全文目录FT_PUBS
6?A7YAmmC0execute sp_fulltext_catalog 'FT_mis','create'
ITPUB个人空间Ielc,}K|SR5]cm
SycT8j0--为title表建立全文索引数据元
ITPUB个人空间3w.NB!o@3x--(注:idx_name 为name of unique index)
ITPUB个人空间+@+P#e:A
g ^execute sp_fulltext_table 'test','create','FT_mis','idx_name'
pJiP0A%r#Fr0o&MPDP c0--设置全文索引列名
ITPUB个人空间s I0r8n&^mt0ca.|execute sp_fulltext_column 'test','descr','add'
J\%K}LB%D'y0execute sp_fulltext_column 'test','name','add'
ITPUB个人空间|e G'a%@ITPUB个人空间Ze e?%}y]7r@--建立全文索引
ITPUB个人空间1?'J6[f:V3z;Q2p["h--activate,是激活表的全文检索能力,也就是在全文目录中注册该表
ITPUB个人空间6zo!@7{3a
M#|sexecute sp_fulltext_table 'test','activate'
ITPUB个人空间ba
L4L:Y,rITPUB个人空间 ?9GWn5Y--填充全文索引目录
A"KC;g X$k'\-VXI0W%{0execute sp_fulltext_catalog 'FT_mis','start_full'
3o|~f*nMT#t e~0L0r?'yI$vz'V$l0--检查全文目录填充情况
ITPUB个人空间*W/g }-t0rWhile (select fulltextcatalogproperty('FT_mis','populateStatus'))<>0
4]5i%\jq7J.T0begin
??7x+pjD0--如果全文目录正处于填充状态,则等待30秒后再检测一次
ITPUB个人空间!rw8lfB&Gwaitfor delay '0:0:30'
ITPUB个人空间4VMghV{_end
7xW8\? SqS0;ZnQvK9T?0--全文目录填充完成后,即可使用全文目录检索
ITPUB个人空间a~.D}9n5qDMiWR%[ UE.K ?wu"L4?0select id, name, descr from test
y_em2r
Tn
C0where contains(name,'夺取')
5{]
kVi0--or contains(descr,'foxfoxmix')
ITPUB个人空间(m8O3q
P1B+rq[Iror freetext(descr,'foxfoxmix')
ITPUB个人空间2I%pSw
Q2BTcH n/`f7yb2O$B_O }0ITPUB个人空间g;w/A-?e,M8a{