Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning! The maximum key length is 900 bytes. The index has maximum length of 1000 bytes

Tags:

sql-server

key

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.

like image 431
ShodowOverRide Avatar asked Mar 04 '14 12:03

ShodowOverRide


People also ask

What is the maximum size of index key?

The maximum size of an index key is 900 bytes.

What is a key length in SQL?

MS SQL Server limits the size of keys to 900 bytes.

How big is varchar max?

The VARCHAR(MAX) data type is similar to the VARCHAR data type in that it supports variable-length character data. VARCHAR(MAX) is different from VARCHAR because it supports character strings up to 2 GB (2,147,483,647 bytes) in length.


2 Answers

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

like image 135
Elsayed Avatar answered Sep 23 '22 01:09

Elsayed


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.

like image 25
Rahul Hera Avatar answered Sep 21 '22 01:09

Rahul Hera