Warning! The maximum key length is 900 bytes. The

2019-02-05 16:13发布

I transfer a db script from a 64 bit system to a 32 bit system. When I execute the script it gives me the following error,

Warning! The maximum key length is 900 bytes. The index 'UQ__Users__7E800015145C0A3F' has maximum length of 1000 bytes. For some combination of large values, the insert/update operation will fail.

Google results and Stack Overflow questions did not help to solve this problem.

3条回答
Ridiculous、
2楼-- · 2019-02-05 16:58

It seems that you are running Microsoft SQL server. Check out Microsoft: Maximum Size of Index Keys for more information about this subject. Or a related answer in: 900 byte index size limit in character length

查看更多
【Aperson】
3楼-- · 2019-02-05 17:03

For indexing columns that have Large sizes ,sqlserver indexes only columns that have size up to 900 bytes.

To solve this problem

Firstly : I added a column hashCol to generate hashcode of Type SHA1 for MyCol

alter table myTable
    add 
    hashCol AS HASHBYTES('SHA1', CONVERT(VARCHAR(90), MyCol))

Secondly : I added a unique constrain for hashCol to uniquely Identify MyCol

 ALTER  TABLE  myTable
     ADD CONSTRAINT hashCol_Unique UNIQUE (hashCol)

By this way I overcame the problem of Indexing columns that have large size

references

Generate Unique hash for a field in SQL Server in-sql-server

查看更多
Lonely孤独者°
4楼-- · 2019-02-05 17:05

Storage length of the varchar type will be +2.

Solution

ALTER TABLE table_name
ALTER COLUMN column_name varchar(255)

so try to reduce the column length to 255 character and try indexing.

查看更多
登录 后发表回答