在 varchar(50) 列与 varchar(2000) 列中插入值时的性能差异?

Difference in performance when inserting a value in a varchar(50) column vs a varchar(2000)?

我正在考虑增加 table 中的一个列的大小,以便它容纳更长的值。但是这个 table 每天都会经历沉重的 INSERTs,我想知道增加大小是否会影响我的 INSERT(和 BULK INSERT)速度。

那么在 VARCHAR(50) 列和 VARCHAR(2000) 列中插入值的执行时间有区别吗?

insert 声明的影响不是您最关心的问题。从数据库中选择数据也可能需要更长的时间,因为行长度变得更长。这将影响读取性能和内存压力。

影响有多大,是否需要担心,取决于查询频率、总行数和可能的索引(在该列或其他列上)。

我建议使用您经常使用的查询在您的环境中进行一些测试并测试其性能。

将 varchar 的长度从 50 更改为 2000 不会有任何影响。

唯一的问题是一旦您开始使用更长的值填充列

来自Microsoft

varchar [ ( n | max ) ]

Variable-length, non-Unicode string data. n defines the string length and can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered + 2 bytes. The ISO synonyms for varchar are char varying or character varying.