为什么我不能创建这个sql server全文索引?

时间:2022-11-04 15:49:42

I have a database table with the primary column defined as:

我有一个数据库表,主列定义为:

ID bigint identity primary key

I also have a text column MiddlePart. I'm trying to create a full text index, like so:

我还有一个文本列MiddlePart。我正在尝试创建一个全文索引,如下所示:

CREATE FULLTEXT INDEX ON domaining.dbo.DomainName
(
    MiddlePart 
    Language 0X0
)
KEY INDEX ID ON domaincatalog
WITH CHANGE_TRACKING AUTO

I get this error:

我收到此错误:

'ID' is not a valid index to enforce a full-text search key. A full-text search key must be a unique, non-nullable, single-column index which is not offline, is not defined on a non-deterministic or imprecise nonpersisted computed column, does not have a filter, and has maximum size of 900 bytes. Choose another index for the full-text key.

“ID”不是强制执行全文搜索键的有效索引。全文搜索键必须是唯一的,不可为空的单列索引,该索引不脱机,未在非确定性或不精确的非持久计算列上定义,没有过滤器,最大大小为900字节。为全文键选择另一个索引。

What am I doing wrong?

我究竟做错了什么?

3 个解决方案

#1


30  

After KEY INDEX, you need to specify the name of the index not the column. To find the name of the index on the column ID, type sp_help DomainName and there will be a list of indexes on that table. The pk will be named something like PK_xxxxx. Use that index name instead of "ID".

在KEY INDEX之后,您需要指定索引的名称而不是列。要在列ID上查找索引的名称,请键入sp_help DomainName,该表上将有一个索引列表。 pk将被命名为PK_xxxxx。使用该索引名称而不是“ID”。

#2


4  

Instead of specifying the column name, specify the name of the index. You can find the name of the primary key index like:

而不是指定列名,请指定索引的名称。您可以找到主键索引的名称,如:

select name from sysindexes where object_id('DomainName') = id

Then you can create a fulltext index like:

然后你可以创建一个全文索引,如:

CREATE FULLTEXT INDEX ON DomainName
(
    MiddlePart 
    Language 0X0
)
KEY INDEX PK__DomainName__40E497F3 ON domaincatalog
WITH CHANGE_TRACKING AUTO

#3


1  

https://www.simple-talk.com/sql/learn-sql-server/understanding-full-text-indexing-in-sql-server/

https://www.simple-talk.com/sql/learn-sql-server/understanding-full-text-indexing-in-sql-server/

CREATE TABLE ProductDocs (
  DocID INT NOT NULL IDENTITY,
  DocTitle NVARCHAR(50) NOT NULL,
  DocFilename NVARCHAR(400) NOT NULL,
  FileExtension NVARCHAR(8) NOT NULL,

      DocSummary NVARCHAR(MAX) NULL,
      DocContent VARBINARY(MAX) NULL,
      CONSTRAINT [PK_ProductDocs_DocID] PRIMARY KEY CLUSTERED (DocID ASC)
    )
CREATE FULLTEXT INDEX ON ProductDocs
(DocSummary, DocContent TYPE COLUMN FileExtension LANGUAGE 1033)
KEY INDEX PK_ProductDocs_DocID
ON ProductFTS
WITH STOPLIST = SYSTEM 

The first line of the statement includes the ON clause, which specifies the table name (in this case, ProductDocs). The statement’s next line is a list of the columns that should be indexed (DocSummary and DocContent).

该语句的第一行包含ON子句,该子句指定表名(在本例中为ProductDocs)。该语句的下一行是应该索引的列的列表(DocSummary和DocContent)。

The next line of the CREATE FULLTEXT INDEX statement in the preceding example is the KEY INDEX clause. This is the name of the unique key index (in this case, PK_ProductDocs_DocID) that is defined on the ProductDocs table. Be sure to specify the index name, and not the column name, when defining your full-text index.

前面示例中CREATE FULLTEXT INDEX语句的下一行是KEY INDEX子句。这是在ProductDocs表上定义的唯一键索引(在本例中为PK_ProductDocs_DocID)的名称。定义全文索引时,请务必指定索引名称,而不是列名称。

Following the KEY INDEX clause in the full-text index definition is the ON clause, which specifies the name of the full-text catalog (ProductFTS) that the index will join. In SQL Server 2008, you can also specify a filegroup where the index will be stored. However, this option isn’t available in SQL Server 2005 because filegroup association is at the catalog level.

全文索引定义中的KEY INDEX子句之后是ON子句,它指定索引将加入的全文目录(ProductFTS)的名称。在SQL Server 2008中,您还可以指定将存储索引的文件组。但是,此选项在SQL Server 2005中不可用,因为文件组关联位于目录级别。

The final clause in the example CREATE FULLTEXT INDEX statement is WITH STOPLIST. This option, available only in SQL Server 2008, lets you specify the name of the stoplist that will be used for this index. In this case, the system stoplist is used, but you can instead specify a user-defined stoplist. (Stoplists are covered in more detail later in the article.)

示例CREATE FULLTEXT INDEX语句中的最后一个子句是WITH STOPLIST。此选项仅在SQL Server 2008中可用,允许您指定将用于此索引的停止列表的名称。在这种情况下,使用系统停止列表,但您可以改为指定用户定义的停止列表。 (本文后面将详细介绍停止名单。)

#1


30  

After KEY INDEX, you need to specify the name of the index not the column. To find the name of the index on the column ID, type sp_help DomainName and there will be a list of indexes on that table. The pk will be named something like PK_xxxxx. Use that index name instead of "ID".

在KEY INDEX之后,您需要指定索引的名称而不是列。要在列ID上查找索引的名称,请键入sp_help DomainName,该表上将有一个索引列表。 pk将被命名为PK_xxxxx。使用该索引名称而不是“ID”。

#2


4  

Instead of specifying the column name, specify the name of the index. You can find the name of the primary key index like:

而不是指定列名,请指定索引的名称。您可以找到主键索引的名称,如:

select name from sysindexes where object_id('DomainName') = id

Then you can create a fulltext index like:

然后你可以创建一个全文索引,如:

CREATE FULLTEXT INDEX ON DomainName
(
    MiddlePart 
    Language 0X0
)
KEY INDEX PK__DomainName__40E497F3 ON domaincatalog
WITH CHANGE_TRACKING AUTO

#3


1  

https://www.simple-talk.com/sql/learn-sql-server/understanding-full-text-indexing-in-sql-server/

https://www.simple-talk.com/sql/learn-sql-server/understanding-full-text-indexing-in-sql-server/

CREATE TABLE ProductDocs (
  DocID INT NOT NULL IDENTITY,
  DocTitle NVARCHAR(50) NOT NULL,
  DocFilename NVARCHAR(400) NOT NULL,
  FileExtension NVARCHAR(8) NOT NULL,

      DocSummary NVARCHAR(MAX) NULL,
      DocContent VARBINARY(MAX) NULL,
      CONSTRAINT [PK_ProductDocs_DocID] PRIMARY KEY CLUSTERED (DocID ASC)
    )
CREATE FULLTEXT INDEX ON ProductDocs
(DocSummary, DocContent TYPE COLUMN FileExtension LANGUAGE 1033)
KEY INDEX PK_ProductDocs_DocID
ON ProductFTS
WITH STOPLIST = SYSTEM 

The first line of the statement includes the ON clause, which specifies the table name (in this case, ProductDocs). The statement’s next line is a list of the columns that should be indexed (DocSummary and DocContent).

该语句的第一行包含ON子句,该子句指定表名(在本例中为ProductDocs)。该语句的下一行是应该索引的列的列表(DocSummary和DocContent)。

The next line of the CREATE FULLTEXT INDEX statement in the preceding example is the KEY INDEX clause. This is the name of the unique key index (in this case, PK_ProductDocs_DocID) that is defined on the ProductDocs table. Be sure to specify the index name, and not the column name, when defining your full-text index.

前面示例中CREATE FULLTEXT INDEX语句的下一行是KEY INDEX子句。这是在ProductDocs表上定义的唯一键索引(在本例中为PK_ProductDocs_DocID)的名称。定义全文索引时,请务必指定索引名称,而不是列名称。

Following the KEY INDEX clause in the full-text index definition is the ON clause, which specifies the name of the full-text catalog (ProductFTS) that the index will join. In SQL Server 2008, you can also specify a filegroup where the index will be stored. However, this option isn’t available in SQL Server 2005 because filegroup association is at the catalog level.

全文索引定义中的KEY INDEX子句之后是ON子句,它指定索引将加入的全文目录(ProductFTS)的名称。在SQL Server 2008中,您还可以指定将存储索引的文件组。但是,此选项在SQL Server 2005中不可用,因为文件组关联位于目录级别。

The final clause in the example CREATE FULLTEXT INDEX statement is WITH STOPLIST. This option, available only in SQL Server 2008, lets you specify the name of the stoplist that will be used for this index. In this case, the system stoplist is used, but you can instead specify a user-defined stoplist. (Stoplists are covered in more detail later in the article.)

示例CREATE FULLTEXT INDEX语句中的最后一个子句是WITH STOPLIST。此选项仅在SQL Server 2008中可用,允许您指定将用于此索引的停止列表的名称。在这种情况下,使用系统停止列表,但您可以改为指定用户定义的停止列表。 (本文后面将详细介绍停止名单。)