如何在MS SQL Server中管理大小可变的字段 [英] How to manage varable sized fields in MS SQL Server
问题描述
我有一张桌子,我想在其中添加一些可变大小的字段.
如果我使用varchar(X),它将始终使用X的空间量.
必须在此字段中插入的数据可能会从10个字节到几MB不等.
我想存储网页数据的这个字段..
m混淆了该字段的适当数据类型..
我该怎么办?
I have table, in which i want to add some variable sized field.
if i use varchar(X) it will always use X amount of space..
the data that have to be inserted in this field can vary from 10 bytes to few MBs..
this field i wants to store webpage data..
m confused abt an appropriate datatype for this field..
How can i do it?
推荐答案
可变长度的非Unicode字符串数据. n定义字符串长度,可以是1到8,000之间的值. max表示最大存储大小为2 ^ 31-1字节(2 GB).存储大小是输入的数据的实际长度+ 2个字节. varchar的ISO同义词是字符变化或字符变化.
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.
因此,varchar(X)
中的X指定可以输入到字段中的字符串的最大长度;但这并不意味着每条记录总是分配X数量的空间.仅分配用于存储放置在字段中的字符串所需的空间.
如果您要存储的字符超过8000个,请使用varchar(max)
.
So X in varchar(X)
specifies the maximum length of the string that can be entered into the field; but it does not mean that X amount of space is always allocated per record. Only the space needed to store the string placed in the field is allocated.
In your case if you are storing more than 8000 characters use varchar(max)
.
这篇关于如何在MS SQL Server中管理大小可变的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!