How do you create a non-clustered index for a string column in SQL Server? [duplicate]

StackOverflow https://stackoverflow.com/questions/15262083

  •  18-03-2022
  •  | 
  •  

문제

I just tried this and got the helpful message that

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

Username is an nvarchar(max) column.

도움이 되었습니까?

해결책

You can't add a index to a nvarchar(max) or varchar(max) column but it can be part of an index.

You can include it in an index but then that index needs to created/rebuilt offline.

Taking a guess from your column name 'Username' I would change the column type to something smaller like a nvarchar(50). The nvarchar(max) datatype can store up to 4Gb of text and is used for more full text storage (in that use you would setup full text searching).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top