Determining Nvarchar length

Deadly 提交于 2019-12-05 02:40:52

Generally it is the same as for varchar really. The number is still the maximum number of characters not the data length.

nvarchar(100) allows 100 characters (which would potentially consume 200 bytes in SQL Server).

You might want to allow for the fact that different cultures may take more characters to express the same thing though.

An exception to this is however is if you are using an SC collation (which supports supplementary characters). In that case a single character can potentially take up to 4 bytes.

So worst case would be to double the character value declared.

You can get the answer with a simple experiment, by executing the code below.

DECLARE @a varchar(4);  SET @a = '123456';  SELECT @a;
DECLARE @b nvarchar(4);  SET @b = '123456';  SELECT @b;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!