MS SQL SERVER 2005È«ÎÄË÷Òý
MS SQL SERVER 2005È«ÎÄË÷Òýѧϰ±Ê¼ÇÒ»
ÏÈÁ˽âÒ»ÏÂÈ«ÎÄË÷ÒýÊÇÈçºÎ´´½¨ºÍʹÓõÄ
´´½¨È«ÎÄË÷Òý:
ÔÚMS SQL SERVER 2005Àï,È«ÎÄË÷ÒýÊÇÒ»¸öµ¥¶ÀµÄ·þÎñÏî,ĬÈÏÊÇÆô¶¯µÄ,µ«ÊÇûÓÐÔÊÐíÊý¾Ý¿âÆôÓÃÈ«ÎÄË÷Òý,Èç¹ûÒªÔÚij¸öÊý¾Ý¿âÖд´½¨È«ÎÄË÷Òý,ÏÈÒªÆôÓÃÊý¾Ý¿âµÄÈ«ÎÄË÷Òý.
ÆôÓ÷½·¨:
1.Êý¾Ý¿â->ÊôÐÔ->³£¹æ->ÆôÓÃÈ«ÎÄË÷Òý --execute sp_fulltext_database 'enable'
2.ÔÚ²éѯÖÐÖ´ÐÐ:,Èç¹ûûÓÐÆôÓþÍÖ´ÐÐÒÔÉÏÆô¶¯Óï¾ä£¬È»ºó´´½¨Ë÷ÒýĿ¼.
--execute sp_fulltext_catalog 'ft_titles', 'create'
ÆôÓÃÁËË÷ÒýÁË,¾Í¿ÉÒÔ´´½¨Ë÷ÒýĿ¼ÁË
ÔÚ²éѯÖÐÖ´ÐÐÒÔÏÂÓï¾ä:
CREATE FULLTEXT CATALOG Ë÷ÒýĿ¼Ãû
Ö´ÐÐÒÔºó,¾Í»áÔÚSQL SERVERµÄ°²×°Ä¿Â¼Àï¿´µ½Ò»¸öͬÃûµÄĿ¼ÃûÁË,·¾¶ÎªMSSQL.1/MSSQL/FTDATA/Ë÷ÒýĿ¼Ãû
ÿ¸ö±íÖ»¿ÉÒÔÓÐÒ»¸öÈ«ÎÄË÷Òý,´æ·ÅÔÚÖ¸¶¨µÄË÷ÒýĿ¼Àï,¿ÉÒÔͨ¹ýÏòµ¼´´½¨,Ò²¿ÉÒÔͨ¹ýSQL´´½¨
»ù±¾Óï·¨:
CREATE FULLTEXT INDEX ON tablename
£¨Ë÷ÒýÁÐ1,Ë÷ÒýÁÐ2...£©
KEY INDEX indexname ON Ë÷ÒýĿ¼Ãû
indexnameÊÇÖ¸ÒÑ´æÔڵĻùÓÚÖ¸¶¨±íµÄΨһË÷ÒýÃû.¶ø²»ÊÇΨһË÷ÒýÁÐÃû.Èç¹ûË÷Òý²»´æÔÚ,ÐèÒªÏÈ´´½¨Î¨Ò»Ë÷Òý.
ʹÓÃÈ«ÎÄË÷Òý:
Ö÷ҪʹÓÃCONTAINS,FREETEXT½øÐвéѯ
¼ÙÉèÒÑÓÐÒ»¸ö±ímusic,ÒÑΪ×Ö¶Îmemo´´½¨È«ÎÄË÷Òý,ÄÇôҪ²éѯº¬ÓÐÖܽÜÂ×»òÕßjayµÄËùÓмǼµÄÓï¾äΪ:
SELECT * from mu
Ïà¹ØÎĵµ£º
1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃExecÖ´ÐÐ
Àý: Select * from tableName
Exec('select * from tableName')
& ......
Óï¾äÐÎʽ£º¡¡ SELECTTOP10*
fromTestTable
WHERE(ID>
¡¡¡¡¡¡¡¡¡¡(SELECTMAX(id)
¡¡¡¡¡¡¡¡from(SELECTTOP20id
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡fromTestTable
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ORDERBYid)AST))
ORDERBYID
SELECTTOPÒ³´óС*
fromTestTable
WHERE(ID>
¡¡¡¡¡¡¡¡¡¡(SELECTMAX(id)
¡¡¡¡¡¡¡¡from(SELECTTOPÒ³´óС*Ò³Êýid
¡¡¡¡¡ ......
Ò»¡¢¼òµ¥²éѯ
¡¡¡¡ ¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣
ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ
±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
SELECT nickname,email
from testtable WHERE name='ÕÅÈý'
(Ò»)Ñ¡ÔñÁбí
¡ ......
if exists(select 1 from sysobjects where name='char_index')
drop function char_index
create function char_index(@string varchar(8000),@char varchar(10),@index smallint)
--@string:´ý²éÕÒ×Ö·û´®£¬@index:²éÕÒλÖÃ
returns smallint
as
begin
declare
@i tinyint,--µ±Ç°ÕÒµ½µÚ@i¸ö
  ......
CREATE Table <±íÃû>
£¨[<ÁÐÃû1>] ÀàÐÍ (³¤¶È) [ȱʡֵ][Áм¶Ô¼Êø]
[£¬<ÁÐÃû2> Êý¾ÝÀàÐÍ[ȱʡֵ][Áм¶Ô¼Êø]]….
[£¬UNIQUE£¨ÁÐÃû[£¬ÁÐÃû]….£©]
[£¬PRIMARY KEY£¨ÁÐÃû[£¬ÁÐÃû]…£©]
&n ......