Previous Next Warning the Maximum Key Length is 900 bytes

数据库中添加索引的时候有可能会产生警告“Warning The maximum key length is 900 bytes……”

 

  创建测试表

CREATE TABLE [dbo].[xtTest](
    [id] [int] NOT NULL,
    [name] [varchar](50) NOT NULL,
    [city] [varchar](400) NOT NULL,
    [description] [varchar](500) NOT NULL
) ON [PRIMARY]

  索引脚本

create index IX_xtTest on xtTest(name,city,description)

  添加索引的时候会产生一个警告

Warning! The maximum key length is 900 bytes. The index ‘IX_xtTest’ has maximum length of 950 bytes. For some combination of large values, the insert/update operation will fail.

当前索引包含的三个字段长度超过了900字节

 

插入一条测试信息

insert into xtTest values(1,'prince','gurgaon','gurgaon is in haryana state')

  可以成功执行数据插入脚本,没有任何异常

 

如果city,description包含更多的字符,比如刚好是400和500个,加上name的字段的几个字符,超过了900

insert into xtTest values(2,'kamal','insert any string containing 400 characters','insert any string containing 500 characters')

  脚本执行失败,并提示The index entry of length 905 bytes for the index ‘IX_xtTest’ exceeds the maximum length of 900 bytes

 

所以不要忽略创建索引时的警告信息,或者确保不会插入超过900字节的内容(不合理的设计)

 

如果必须将description这样的字段添加到索引,建议这样做

create index IX_xtTest on xtTest(name,city)
include(description)

  

posted on 2016-05-06 09:50  capad 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/clith/p/5464523.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值