我有一个像这样创建的视图:
CREATE VIEW [dbo].[vwData] WITH SCHEMABINDING
AS
SELECT [DataField1] ,
[DataField2] ,
[DataField3]
FROM dbo.tblData
当我尝试在其上创建全文索引时,如下所示:
CREATE FULLTEXT INDEX ON [dbo].[vwData](
[DataField] LANGUAGE [English])
KEY INDEX [idx_DataField]ON ([ft_cat_Server], FILEGROUP [PRIMARY])
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
我收到此错误:
View 'dbo.vwData' is not an indexed view.
Full-text index is not allowed to be created on it.
知道为什么吗?
答案 0 :(得分:13)
首先,您需要在创建全文索引之前在视图上创建唯一的聚簇索引。
假设你有一张桌子:
CREATE TABLE [dbo].[tblData](
[DataField1] [Varchar] NOT NULL,
[DataField2] [varchar](10) NULL,
[DataField3] [varchar](10) NULL
)
正如您已经做过的那样,您有一个观点:
CREATE VIEW [dbo].[vwData]
WITH SCHEMABINDING
AS
SELECT [DataField1] ,
[DataField2] ,
[DataField3]
FROM dbo.tblData
GO
现在您需要在视图上创建唯一的聚簇索引:
CREATE UNIQUE CLUSTERED INDEX idx_DataField
ON [dbo].[vwData] (DataField1);
GO
创建唯一键后,因为您已经有全文目录 ft_cat_Server ,您可以创建全文索引:
CREATE FULLTEXT INDEX ON [dbo].[vwData](
[DataField1] LANGUAGE [English])
KEY INDEX [idx_DataField]ON ([ft_cat_Server], FILEGROUP [PRIMARY])
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
希望这会有所帮助:)
答案 1 :(得分:7)
您必须通过创建唯一的聚簇索引来使您的视图编入索引:
create unique clustered index ix_vwData on vwData(<unique columns>)
之后,索引idx_DataField
必须是唯一的,不可为空的单列索引。