zygimantas
zygimantas

Reputation:

NVarchar(MAX) for short strings

I am interested is NVarchar(MAX) a good data type is I want to store short unicode strings which are 1-50 characters long, but most of them (more than 90%) are 5-10 characters long?

The column will not be used in comparison and ordering queries. It might be added to index as included column. Expected rows count - more than 10M.

Any recommendations? Thank you in advance!

Upvotes: 3

Views: 5287

Answers (3)

azheglov
azheglov

Reputation: 5523

NVARCHAR(MAX) (which I believe is the same as NTEXT in the earlier versions of SQL server) is intended for storing long text values of variable and potentially unlimited length.

If you know the values won't exceed N characters, you should use NVARCHAR(N).

Upvotes: 1

beach
beach

Reputation: 8640

I would suggest that nvarchar(50) is more appropriate if the maximum length is indeed 50.

Upvotes: 1

DCNYAM
DCNYAM

Reputation: 12126

Why would you use nvarchar(MAX) for such short strings? If you know the maximum length is 50 characters, make it nvarchar(50).

Also, I do not believe an nvarchar(MAX) column can be included in an index as it would break the 900 byte limit.

Upvotes: 6

Related Questions