SQL Server 2008在包含复合主键的表上进行全文搜索

编程入门 行业动态 更新时间:2024-10-27 18:33:21
本文介绍了SQL Server 2008在包含复合主键的表上进行全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在SQL Server 2008上进行全文搜索,但是我想索引的表是一个包含复合主键的表,如下所示:

EXEC sp_fulltext_catalog'My_Catalog','create' EXEC sp_fulltext_table'Message','create','My_Catalog','PK__MESSAGES__C87C0C9C0EC32C7A'// PK__MESSAGES__C87C0C9C1EC32C6A is a composite key

我得到以下错误:'PK__MESSAGES__C87C0C9C1EC32C6A'不是一个有效的强制索引一个全文搜索关键字全文搜索关键字必须是一个唯一的,不可为空的单列索引,它不脱机,未在非确定性或不精确的非计算列上定义,没有过滤器,最大大小为900字节,为全文键选择另一个索引。

这意味着我不能在表格中使用全文搜索复合主键?或者我做错了什么?

预先致谢 我认为错误信息很明显,不是吗?

PK_MESSAGES_C87C0C9C1EC32C6A 不是a有效索引执行全文搜索键全文搜索键必须是唯一的,不可为空的单列索引不是脱机,没有在中定义非确定性或不精确的非计算列,不具有过滤器,并且具有最大值 900字节。为全文键选择另一个索引。

如果您的索引不是唯一的,而不是非空,而不是单列,它不能用于全文索引。

这意味着我无法使用在具有复合主键的表中完整的文本搜索?或者我做了什么错误?

不,如错误所述 - 这种索引不起作用。期。没有办法绕过它。

Remus指出 - 它从未说过它必须是主键索引!如果表格上还有其他不可空的且唯一的字段,则可以在该字段上使用唯一的索引。你甚至可以简单地在你的表中添加一个 INT IDENTITY(1,1)字段并在其上放置一个 UNIQUE INDEX 那个单一的领域,你应该很好去。

I am trying to put full text search working on SQL Server 2008, however the table i am trying to index is a table with a composite primary key, something like this:

EXEC sp_fulltext_catalog 'My_Catalog', 'create' EXEC sp_fulltext_table 'Message', 'create', 'My_Catalog', 'PK__MESSAGES__C87C0C9C0EC32C7A' // PK__MESSAGES__C87C0C9C1EC32C6A is a composite key

and i get the following error: "'PK__MESSAGES__C87C0C9C1EC32C6A' 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."

This means that i can't use the full text search in tables with composite primary keys? Or am i doing something wrong?

Thanks in advance

解决方案

I think the error message is pretty clear, no?

"PK_MESSAGES_C87C0C9C1EC32C6A 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."

If your index is not unique, not non-nullable, and not single-column, it cannot be used for fulltext indexing.

This means that i can't use the full text search in tables with composite primary keys? Or am i doing something wrong?

No, as the error says - this kind of index will not work. Period. No way around it.

As Remus pointed out - it doesn't ever say it has to be the primary key index! If you have some other non-nullable and unique field on the table, you can use a unique index on that field for your purposes. You could even just simply add a INT IDENTITY(1,1) field to your table and put a UNIQUE INDEX on that single field and you should be good to go.

更多推荐

SQL Server 2008在包含复合主键的表上进行全文搜索

本文发布于:2023-10-22 09:22:00,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键   表上   全文   SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!