varchar(500) 比 varchar(8000) 有优势吗? [英] is there an advantage to varchar(500) over varchar(8000)?

查看:23
本文介绍了varchar(500) 比 varchar(8000) 有优势吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 MSDN 论坛和这里阅读了相关内容,但我仍然不清楚.我认为这是正确的: Varchar(max) 将存储为文本数据类型,因此有缺点.因此,假设您的字段可靠地少于 8000 个字符.就像我的数据库表中的 BusinessName 字段.实际上,公司名称可能总是低于(从我的帽子里拿出一个数字)500 个字符.我遇到的很多 varchar 字段似乎都低于 8k 字符数.

I've read up on this on MSDN forums and here and I'm still not clear. I think this is correct: Varchar(max) will be stored as a text datatype, so that has drawbacks. So lets say your field will reliably be under 8000 characters. Like a BusinessName field in my database table. In reality, a business name will probably always be under (pulling a number outta my hat) 500 characters. It seems like plenty of varchar fields that I run across fall well under the 8k character count.

那么我应该将该字段设为 varchar(500) 而不是 varchar(8000) 吗?从我对 SQL 的理解来看,这两者之间没有区别.因此,为了方便起见,我想将所有 varchar 字段定义为 varchar(8000).这有什么缺点吗?

So should I make that field a varchar(500) instead of varchar(8000)? From what I understand of SQL there's no difference between those two. So, to make life easy, I'd want to define all my varchar fields as varchar(8000). Does that have any drawbacks?

相关:varchar 列的大小(我不觉得这个回答了我的题).

Related: Size of varchar columns (I didn't feel like this one answered my question).

推荐答案

从处理的角度来看,使用 varchar(8000) 与使用 varchar(500) 没有区别.定义字段应容纳的最大长度并使您的 varchar 成为该长度,这更像是一种良好实践".它可用于协助数据验证.例如,将州缩写设为 2 个字符或将邮政编码设为 5 或 9 个字符.当您的数据与字段长度至关重要的其他系统或用户界面(例如大型机平面文件数据集)交互时,这曾经是一个更重要的区别,但现在我认为这比其他任何事情都更习惯.

From a processing standpoint, it will not make a difference to use varchar(8000) vs varchar(500). It's more of a "good practice" kind of thing to define a maximum length that a field should hold and make your varchar that length. It's something that can be used to assist with data validation. For instance, making a state abbreviation be 2 characters or a postal/zip code as 5 or 9 characters. This used to be a more important distinction for when your data interacted with other systems or user interfaces where field length was critical (e.g. a mainframe flat file dataset), but nowadays I think it's more habit than anything else.

这篇关于varchar(500) 比 varchar(8000) 有优势吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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