如何解决 SQL Server 2005 中数据类型为 varchar(4096) 的列上的 900 个键长度限制索引?

发布于 2024-09-04 04:59:25 字数 438 浏览 3 评论 0原文

这是创建索引的查询 在 BFPRODATTRASSOCIATION (value,attributeid) include (productid)

BFPRODATTRASSOCIATION

ProdAttrAssociationId bigint no 8
ProductId             bigint no 8
AttributeId           bigint  no  8
Value                 varchar no 4096

上创建索引 idx_ncl_2我收到此错误:

最大密钥长度为 900 字节。索引“idx_ncl_2”的最大长度为 1237 字节。

我必须在此列上创建非聚集索引。有什么方法可以为数据类型为 varchar 且大小大于 900 的列创建索引。

请建议。

This is the query for creating index
create index idx_ncl_2 on BFPRODATTRASSOCIATION (value,attributeid) include (productid)

Table structure of BFPRODATTRASSOCIATION

ProdAttrAssociationId bigint no 8
ProductId             bigint no 8
AttributeId           bigint  no  8
Value                 varchar no 4096

I am getting this error:

The maximum key length is 900 bytes. The index ‘idx_ncl_2’ has maximum length of 1237 bytes.

I have to create a nonclustered index on this column. Is there any way i can create index for the column which have datatype of varchar and size is greater than 900.

Please suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情癖 2024-09-11 04:59:25

你不能 - 正如错误消息已经明确指出的那样,任何索引条目的长度都不能超过 900 字节。

您无法对 varchar(4096) 字段 - 句点建立索引。没有办法解决这个问题 - 这是 SQL Server 的硬限制 - 无法配置它、更改它、使其更大。请参阅联机丛书 - 索引键的最大大小进行确认。

您需要将“值”列限制为小于 900 字节,或者找到另一种方法来存储该数据 - 或者只是不将其包含在索引中。如果您只希望索引中的“值”字段具有覆盖索引(以便能够满足索引条目的查询),则可以将该字段移动为索引中的包含列 - 不低于 900 字节限制。

CREATE NONCLUSTERED INDEX idx_ncl_2 
  ON BFPRODATTRASSOCIATION(attributeid) 
  INCLUDE (productid, value)

该索引应该有效。

You can't - as the error message already clearly states, any index entry cannot be more than 900 bytes long.

You cannot index a varchar(4096) field - period. No way around that - it's a hard SQL Server limit - no way to configure it, change it, make it bigger. See Books Online - Maximum Size of Index Keys for confirmation.

You need to either limit your "value" column to less than 900 bytes, or find another way to store that data - or just not include it in the index. If you only want your "value" field in the index to have a covering index (to be able to satisfy queries from the index entry), you could move the field to be an included column in the index - those don't fall under the 900 byte limit.

CREATE NONCLUSTERED INDEX idx_ncl_2 
  ON BFPRODATTRASSOCIATION(attributeid) 
  INCLUDE (productid, value)

That index should work.

暗喜 2024-09-11 04:59:25

您可以在计算列上创建索引,该列是字符串。请参阅 T-SQL 中的哈希函数使用哈希键的智能数据库设计了解一些想法和限制。

You could create and index on a computed column that is the hash of the string. See Hash functions in T-SQL and Intelligent Database Design Using Hash Keys for some ideas and limitations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文