为什么不使用varchar(max)? [英] Why not use varchar(max)?

查看:156
本文介绍了为什么不使用varchar(max)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库设计方面,我有点老了,所以我完全赞成在列中使用正确的数据大小.但是,在查看一个朋友的数据库时,我注意到他经常使用varchar(max).现在,我立即想到的是将其退还给他,并告诉他进行更改.但是后来我考虑了一下,不能为他不使用它提供一个很好的理由(如果您想知道的话,他曾使用过一个案例类型工具来生成数据库).

I'm a bit old school when it comes to database design, so I'm totally for using the correct data sizes in columns. However, when reviewing a database for a friend, I noticed he used varchar(max) a lot. Now, my immediate thought was to throw it back to him and tell him to change it. But then I thought about it and couldn't come up with a good reason for him not to use it (he'd used a case type tool to generate the db, if you're wondering).

我一直在研究varchar(max)用法的主题,我不能为他不使用它提供任何充分的理由.

I've been researching the topic of varchar(max) usage and I can't really come up with any good reason for him not to use it.

他不使用列作为索引,位于数据库上的应用程序对输入有限制,因此不允许在字段中输入大量条目.

He doesn't use the columns for indexes, the application that sits on the db has limitations on the input, so it won't allow massive entries in the fields.

我们将不胜感激,帮助我让他见识光芒:).

Any help would be appreciated to help me make him see the light :).

推荐答案

我对此的回答与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.

这篇关于为什么不使用varchar(max)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆