nvarchar(n) 到底是什么意思

What exactly is the meaning of nvarchar(n)

文档不是很清楚:https://msdn.microsoft.com/en-us/library/ms186939.aspx

如果我尝试将 20 个字符长度的字符串存储在定义为 nvarchar(10) 的列中,会发生什么情况? 10 是字段的最大长度还是预期长度?如果我可以在字符串中超过 n 个字符,这样做对性能有何影响?

根据我的理解,nvarchar 只会存储提供的字符,最多不超过定义的数量。 Nchar实际上会用空格填充未使用的字符。

您可以在列或变量中存储的最大字符数 nvarchar(n)n。如果您尝试存储更多字符串,您的字符串将被截断,或者在插入 table 的情况下,插入将被禁止,并发出有关可能截断的警告:

String or binary data would be truncated. The statement has been terminated.

declare @n nvarchar(10)
set @n = N'more than ten chars'
select @n

结果:

----------
more than 

(1 row(s) affected)