sql - nvarchar(4001)?

标签 sql sql-server tsql sql-server-2008

MSDN has this to say关于主题:

nvarchar [ ( n | max ) ]

Variable-length Unicode character data. ncan be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for nvarchar are national char varying and national character varying.

这让我很困惑。我可以将一列定义为 1 - 4000 长,或 2147483647 长但两者之间什么都没有?我的理解正确吗?为什么我不能明确说明两者之间的值?

最佳答案

NVARCHAR(MAX) 涵盖所有其他内容(不仅仅是 20 亿个字符)。如果您需要超过 4,000 个字符,数据肯定会超出页面,因此就行为而言,您使用了 4,001 个字符、10,000 个字符还是 10,000,000 个字符都没有关系。它只占用您需要的空间,所以不要认为您在浪费 (20 亿个字符 - 实际字符串的长度)

关于sql - nvarchar(4001)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6929969/

相关文章:

sql - 复合主键限制?

c# - 如何使用 SMO 将数据库传输到新模式?

Java 64 位 JDBC-ODBC 驱动程序问题

sql - 检查 SQL 中的字段是否包含特定的字母数字格式

sql - 如何格式化 Oracle SQL 纯文本选择输出

php - 如何构建 SQL 查询以从两个表和一个序列化列获取数据

sql-server - 在 where 条件下使用 Sql server 列别名

sql-server - 使用 count() 构建 sql 查询,其中 count() > 1

mysql - SQL 获取非规范化表中某指定信息对应的第一个字段

c# - 在MVC中调用存储过程