Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÈçºÎÔÚSQLÖÐÆôÓÃÈ«ÎļìË÷¹¦ÄÜ

ÈçºÎÔÚSQLÖÐÆôÓÃÈ«ÎļìË÷¹¦ÄÜ£¿
¡¡¡¡--------------------------------------------------------------------------------
¡¡¡¡È«ÎÄË÷ÒýµÄÒ»¸öÀý×Ó£¬ÔÚ²éѯ·ÖÎöÆ÷ÖÐʹÓãº
¡¡¡¡use pubs
¡¡¡¡go
¡¡¡¡--´ò¿ªÊý¾Ý¿âÈ«ÎÄË÷ÒýµÄÖ§³Ö
¡¡¡¡execute sp_fulltext_database 'enable'
¡¡¡¡go
¡¡¡¡--½¨Á¢È«ÎÄĿ¼ft_titles
¡¡¡¡execute sp_fulltext_catalog 'ft_titles', 'create'
¡¡¡¡go
¡¡¡¡--Ϊtitles±í½¨Á¢È«ÎÄË÷ÒýÊý¾ÝÔª£¬UPKCL_titleidindÊÇÖ÷¼üËù½¨Á¢µÄΨһË÷Òý£¬¿ÉÓÉsp_help titlesµÃÖª
¡¡¡¡execute sp_fulltext_table 'titles','create', 'ft_titles', 'UPKCL_titleidind'
¡¡¡¡go
¡¡¡¡--ÉèÖÃÈ«ÎÄË÷ÒýÁÐÃû
¡¡¡¡exec sp_fulltext_column 'titles', 'title', 'add'
¡¡¡¡go
¡¡¡¡exec sp_fulltext_column 'titles', 'notes', 'add'
¡¡¡¡go
¡¡¡¡--½¨Á¢È«ÎÄË÷Òý
¡¡¡¡exec sp_fulltext_table 'titles', 'activate'
¡¡¡¡go
¡¡¡¡--Ìî³äÈ«ÎÄË÷ÒýĿ¼
¡¡¡¡exec sp_fulltext_catalog 'ft_titles', 'start_full'
¡¡¡¡go
¡¡¡¡--ʹÓÃcontainsºÍfreetext
¡¡¡¡select title, notes from titles
¡¡¡¡where contains(title, '"computer Cooking"')
¡¡¡¡go
¡¡¡¡select title, notes from titles
¡¡¡¡where freetext(title, 'computer Cooking')
¡¡¡¡go
¡¡¡¡select title, notes from titles
¡¡¡¡where freetext(title, '"computer Cooking"')
¡¡¡¡go
¡¡¡¡select title, notes from titles
¡¡¡¡where contains(title, 'computer')
¡¡¡¡go
¡¡¡¡select title, notes from titles
¡¡¡¡where freetext (*, 'computer')
¡¡¡¡go
------------------------------------------------------------------------------------------------------
ʾÀý
SQL SERVERÊý¾Ý¿âÈ«ÎÄË÷ÒýµÄʾÀý£¬ÒÔpubsÊý¾Ý¿âΪÀý¡£
Ê×ÏÈ£¬½éÉÜÀûÓÃϵͳ´æ´¢¹ý³Ì´´½¨È«ÎÄË÷ÒýµÄ¾ßÌå²½Ö裺
1) Æô¶¯Êý¾Ý¿âµÄÈ«ÎÄ´¦Àí¹¦ÄÜ (sp_fulltext_database)
2) ½¨Á¢È«ÎÄĿ¼ (sp_fulltext_catalog)
3) ÔÚÈ«ÎÄĿ¼ÖÐ×¢²áÐèҪȫÎÄË÷ÒýµÄ±í (sp_fulltext_table)
4) Ö¸³ö±íÖÐÐèҪȫÎÄË÷ÒýµÄÁÐÃû (sp_fulltext_column)
5) Ϊ±í´´½¨È«ÎÄË÷Òý (sp_fulltext_table)
6) Ìî³äÈ«ÎÄĿ¼ (sp_fulltext_catalog)
---------********ʾÀý********-------------
ÒÔ¶ÔpubsÊý¾Ý¿âµÄtitleºÍnotesÁн¨Á¢È«ÎÄË÷Òý£¬Ö®ºóʹÓÃË÷Òý²éѯtitleÁлònotesÁÐÖаüº¬ÓÐdatebase »òcomputer×Ö·û´®µÄͼÊéÃ


Ïà¹ØÎĵµ£º

SQLµ±Ç°ÈÕÆÚ»ñÈ¡¼¼ÇÉ

SQLµ±Ç°ÈÕÆÚ»ñÈ¡¼¼ÇÉ
select   getdate()   //2003-11-07   17:21:08.597    
  select   convert(varchar(10),   getdate(),120)   //2003-11-07  
  select   convert(char(8),getdate(),112)  ......

SQL·ÖÒ³ ÀûÓÃID´óÓÚ¶àÉÙºÍSELECT TOP·ÖÒ³

Óï¾äÐÎʽ£º¡¡ SELECTTOP10*
fromTestTable
WHERE(ID>
¡¡¡¡¡¡¡¡¡¡(SELECTMAX(id)
¡¡¡¡¡¡¡¡from(SELECTTOP20id
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡fromTestTable
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ORDERBYid)AST))
ORDERBYID
SELECTTOPÒ³´óС*
fromTestTable
WHERE(ID>
¡¡¡¡¡¡¡¡¡¡(SELECTMAX(id)
¡¡¡¡¡¡¡¡from(SELECTTOPÒ³´óС*Ò³Êýid
¡¡¡¡¡ ......

SQL Server Óï¾ä²éѯÊÖ²á

½¨±í£º
CREATE TABLE  [DB.dbo].tableName
(Stud_id int CONSTRAINT  constraintName1  not null primary key,
 Name nvarchar(5) not null,
 Birthday datetime,
 Gender nchar(1),
 Telcode char(12),
 Zipcode char(6) CONSTRAINT constraintName2 CHECK(zipcode like [ ......

SQL²éѯÓï¾äʹÓÃ

Ò»¡¢¼òµ¥²éѯ
¡¡¡¡ ¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣
ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ
±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
SELECT nickname,email
from testtable WHERE name='ÕÅÈý'
(Ò»)Ñ¡ÔñÁбí
¡ ......

sql²éÕÒij¸ö×Ö·û´®µÚN´Î³öÏÖµÄλÖõĺ¯Êý(תÌû)

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¸ö
  ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ