可变长度字符类型,在TSql中使用varchar(n) 和 nvarchar(n)来表示,但是N取值范围是多少?
declare @nv_max varchar(9000) declare @nv_min varchar(0) select @nv_max select @nv_min
消息 131,级别 15,状态 3,第 1 行
赋予 类型 ‘varchar‘ 的大小(9000)超出了任意数据类型的最大允许值(8000)。
消息 1001,级别 15,状态 1,第 2 行
第 2 行: 指定的长度或精度 0 无效。
消息 137,级别 15,状态 2,第 3 行
必须声明标量变量 "@nv_max"。
消息 137,级别 15,状态 2,第 4 行
必须声明标量变量 "@nv_min"。
由此可见,N的取值范围的上限是8000,下限自然是1,可变长度字符类型的取值范围是[1-8000]。
varchar(max)和nvarchar(max),max突破长度8000的上限,达到LOB的最大值2G。
The size of values specified with MAX can reach the maximum size supported by LOB data, which is currently 2GB.
Because the max data types can store LOB data as well as regular row data, you are recommanded to use these data types in future development in place of the text, ntext, or image tyes, which MS has indicated will be removed in a future version.
varchar(n) 和 nvarchar(n), N值的最大值
原文:http://www.cnblogs.com/ljhdo/p/4983828.html