is of a type that is invalid for use as a key column in an index

后端 未结 5 2011
我在风中等你
我在风中等你 2020-11-29 21:57

I have an error at

Column \'key\' in table \'misc_info\' is of a type that is invalid for use as a key column in an index.

where key is a n

5条回答
  •  隐瞒了意图╮
    2020-11-29 22:41

    A unique constraint can't be over 8000 bytes per row and will only use the first 900 bytes even then so the safest maximum size for your keys would be:

    create table [misc_info]
    ( 
        [id] INTEGER PRIMARY KEY IDENTITY NOT NULL, 
        [key] nvarchar(450) UNIQUE NOT NULL, 
        [value] nvarchar(max) NOT NULL
    )
    

    i.e. the key can't be over 450 characters. If you can switch to varchar instead of nvarchar (e.g. if you don't need to store characters from more than one codepage) then that could increase to 900 characters.

提交回复
热议问题