我目前正在尝试添加一个FULLTEXT索引,以便能够在叙述列中搜索包含关键词的关键词。我已经尝试了很多不同的教程,虽然我完全复制它们但是在'WHERE'部分中使用'CONTAINS'功能时我无法复制结果。
以下是我一直使用的一些示例数据的脚本示例。有人能够向我解释为什么这不起作用,因为我正在努力查看错误可能存在的位置。
CREATE TABLE dbo.AAAA_FullTextTest5
(ID INT Identity(1, 1) NOT NULL
,LOCATION VARCHAR (255)
,NARRATIVE VARCHAR(MAX)
)
ALTER TABLE dbo.AAAA_FullTextTest5 add constraint PK_FullTextTest5 PRIMARY KEY (ID)
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('USA Texas', 'WRIGHT BROTHERS')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Worldwide', 'CROWN PROS Builders LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Devon United Kingdom', 'J PJH ROOFING LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('UK', 'Shoreham Port Authority and Shoreham Port Developments & The Port of Shoreham Trustees ')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('EUROPE AND RUSSIA', 'ZHY SERVICES')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Austrialia', 'BrotherLimited')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('ASIA', 'DRILLING SERVICES LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('JAPAN', 'BROOKS WASTE LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Melbourne', 'TRC Service Company')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('GERMANY & HOLLAND', 'Samson Group')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Frankfurt', 'SCAFFOLDING LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Swindon, England', 'Scaffold Access Ltd')
CREATE FULLTEXT CATALOG FullTextTest5
CREATE FULLTEXT INDEX ON dbo.AAAA_FullTextTest5 (
Location language 1033
,Narrative language 1033)
KEY INDEX PK_FullTextTest5 ON FullTextTest5
WITH CHANGE_TRACKING AUTO
SELECT * FROM dbo.AAAA_FullTextTest5
WHERE CONTAINS(NARRATIVE, 'Access')
答案 0 :(得分:0)
根据此处的说明:https://msdn.microsoft.com/en-us/library/ms142497.aspx,以下内容似乎可以在我本地安装的SQL Server 2008 R2中正常运行,以及我本地安装的SQL Server 2012:
CREATE TABLE dbo.AAAA_FullTextTest5
(ID INT Identity(1, 1) NOT NULL
,LOCATION VARCHAR (255)
,NARRATIVE VARCHAR(MAX)
)
GO
CREATE UNIQUE INDEX UI_AAAA_FullTextTest5 ON dbo.AAAA_FullTextTest5(ID)
GO
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('USA Texas', 'WRIGHT BROTHERS')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Worldwide', 'CROWN PROS Builders LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Devon United Kingdom', 'J PJH ROOFING LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('UK', 'Shoreham Port Authority and Shoreham Port Developments & The Port of Shoreham Trustees ')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('EUROPE AND RUSSIA', 'ZHY SERVICES')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Austrialia', 'BrotherLimited')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('ASIA', 'DRILLING SERVICES LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('JAPAN', 'BROOKS WASTE LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Melbourne', 'TRC Service Company')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('GERMANY & HOLLAND', 'Samson Group')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Frankfurt', 'SCAFFOLDING LTD')
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Swindon, England', 'Scaffold Access Ltd')
GO
CREATE FULLTEXT CATALOG AAAA_FTCat;
GO
CREATE FULLTEXT INDEX ON AAAA_FullTextTest5
(
NARRATIVE --Full-text index column name
Language 2057 --2057 is the LCID for British English
)
KEY INDEX UI_AAAA_FullTextTest5 ON AAAA_FTCat --Unique index
WITH CHANGE_TRACKING AUTO --Population type;
GO
通过上面的设置,我可以查询:
SELECT * FROM AAAA_FullTextTest5
WHERE CONTAINS(NARRATIVE, 'Access')
获得此结果集:
ID LOCATION NARRATIVE
12 Swindon, England Scaffold Access Ltd