简体   繁体   中英

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

I have a temporary variable with a computed column based on SHA1 hasbyte. When I create a UNIQUE non clustered index on the computed column, it throws the warning::

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

I remember reading out put of SHA1 byte being limited to some 160 bytes. I'm unable to understand why I get this warning.

If check the max length of all the columns involved in computed column by the below query it adds up to some 8148 bytes. But i thought with the hash I'm using I should get not more than 160 bytes for the computed column.

SELECT Sum(c.max_length)
FROM SYS.COLUMNS C INNER JOIN SYS.TABLES tb ON tb.[object_id] = C.  [object_id]
INNER JOIN SYS.TYPES T ON C.system_type_id = T.user_type_id
WHERE tb.[is_ms_shipped] = 0
and OBJECT_NAME(tb.object_id)='xyz'

Please advise what I'm missing here.

Im not expert on Hash:

But I suggest you create a column combine varchar(750) (15*50)

Then update that column with SET combine = Col1+ Col2+ Col3+.. Col15

And try:

CompSum AS HashBytes('SHA1', combine)

That way you are using a field which will never be bigger than 750

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM