且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么不使用varchar(max)?

更新时间:2023-11-13 23:03:16

我对此的回答与Max的使用无关,与VARCHAR(max)vs TEXT的原因无关.

My answer to this, isn't about the usage of Max, as much as it is about the reason for VARCHAR(max) vs TEXT.

在我的书中;首先,除非您可以绝对确定除了英语文本之外,否则您都不会编码任何东西,而且人们不会引用异国名称,那么您应该使用NVARCHAR或NTEXT.

In my book; first of all, Unless you can be absolutely certain that you'll never encode anything but english text and people won't refer to names of foreign locations, then you should use NVARCHAR or NTEXT.

第二,这是您可以使用的字段.

Secondly, it's what the fields allow you to do.

与VARCHAR相比,TEXT很难更新,但是您可以利用全文索引和许多巧妙的功能.

TEXT is hard to update in comparison to VARCHAR, but you get the advantage of Full Text Indexing and lots of clever things.

另一方面,如果像元的大小是<,则VARCHAR(MAX)具有一些歧义. 8000个字符,它将被视为行数据.如果更大,则出于存储目的,它将被视为LOB. 由于不查询RBAR就无法知道这一点,因此对于需要确定数据及其读取成本的地方,这可能具有优化策略.

On the other hand, VARCHAR(MAX) has some ambiguity, if the size of the cell is < 8000 chars, it will be treated as Row data. If it's greater, it will be treated as a LOB for storage purposes. Because you can't know this without querying RBAR, this may have optimization strategies for places where you need to be sure about your data and how many reads it costs.

否则,如果您的使用情况相对平凡,并且您不希望数据大小出现问题(即,您使用的是.Net,因此不必担心字符串/字符的大小*对象),然后使用VARCHAR(max)就可以了.

Otherwise, if your usage is relatively mundane and you don't expect to have problems with the size of data (IE you're using .Net and therefore don't have to be concerned about the size of your string/char* objects) then using VARCHAR(max) is fine.