user1277327
user1277327

Reputation: 421

Confused about nvarchar limit

I've got a quick question that I can't find an answer to anywhere. I frequently need to convert one type of database to another, therefor I'm writing a program to convert MS SQL Server databases back and forth. The problem I'm having is that I can't declare an nvarchar variable with a max length of above 4000. I get,

"The size (6000) given to the parameter 'description' exceeds the maximum allowed (4000)."

Yet that is clearly defined as an nvarchar(6000) in the original database, at least I think so because max_length is 6000, if you use max max_length is -1, right? I know I could just use nvarchar(max) but if I'm writing software that converts databases I want to stay as true to the original as possible.

Was the nvarchar max limit changed recently or is it some setting that I've missed?

Upvotes: 8

Views: 12067

Answers (1)

Jitendra Gupta
Jitendra Gupta

Reputation: 824

The given size (6000) is in bytes where as when you give the length, it is in number of chars of unicode. The limit 4000 is because internal storage of nvarchar(xxxx) and nvarchar(max) is different. If you want more storage than 4000 char, use nvarchar(max).

Upvotes: 8

Related Questions