[英]Memory Usage in SQL Server?
I have been thinking about database design lately and I have the following question:我最近一直在考虑数据库设计,我有以下问题:
When a type, say a varchar(max), is set for a column is 2GB of space set aside every time a row is inserted?当为列设置类型(例如 varchar(max))时,每次插入一行时预留 2GB 的空间?
Or is the space allocated on the server equal to the amount of data in the column?还是服务器上分配的空间等于列中的数据量?
Thanks!谢谢!
The varchar
data type in SQL Server and elsewhere means roughly variable-length character data. SQL Server 和其他地方的
varchar
数据类型大致表示可变长度的字符数据。 The max
or any other constant value represents its upper bound and not its absolute size. max
或任何其他常数值表示其上限,而不是其绝对大小。 So your latter observation is correct:所以你后面的观察是正确的:
the space allocated on the server equal to the amount of data in the column
服务器上分配的空间等于列中的数据量
Now, if you define something like char(200)
(notice the lack of var in front of char there) then yes, 200 characters are allocated regardless of how much data (up to 200 chars) you store in that field.现在,如果您定义类似
char(200)
的内容(请注意 char 前面缺少 var),那么是的,无论您在该字段中存储多少数据(最多 200 个字符),都会分配 200 个字符。 The maximum upper bound for the char
data type is 8000, by the way.顺便说一下,
char
数据类型的最大上限是 8000。
Of course not:)当然不是:)
Varchar(max)
is a
bastardised
hybrid data type
(if you do not mind me being a bit frank)
: Varchar(max)
是一种
混杂
的混合数据类型
(如果你不介意我有点坦率的话)
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.