为什么mysql有很多不同的字段类型?

发布于 2024-11-08 03:05:33 字数 183 浏览 2 评论 0原文

既然数据被分类为 int、decimal、text(string)、date、enum,为什么 mysql 还需要将它们分类更多的组,就像文本分为 char、varchar、text、tinytext 等?我知道这会让它更快,但是分类到更多组和让它更快之间有什么关系呢?原因是什么?

抱歉我的英语不好。

Since data is categorized as int, decimal, text(string), date, enum, Why mysql still need to categorized them into more groups like text is seperated into char, varchar, text, tinytext, etc? I knew this would make it faster, but what is the relation between categorized into more groups and making it faster? What is the reason?

Sorry for my poor english.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-11-15 03:05:33

那么背后的主要原因是内存。看到地址是一个文本信息,名称是一个文本信息,如果你想存储任何值像yesno也是一个文本值,如果你想取来自任何人的评论或帖子也是一个 text 值。所有这些价值观都需要不同的记忆。当您谈论大型系统时,内存是一个重要因素。例如,如果您为所有文本信息设置 text 类型,那么这是一种非常糟糕的做法。所以mysql已经分为不同的东西了。就像如果你想存储名称,你可以使用varchar(50),如果你想存储地址,你甚至可以使用varchar(255)。如果您想存储帖子或评论和描述或任何内容,您可以使用text。如果您想使用 yesno 之类的信息,您可以使用 char。我希望你明白。

Well the main reason behind is the memory. See the address is a text information, name is a text information, if you want to store any value like yes and no is also a text value, If you want to take the comment or post from any one it is also a text value. All these values needs different memories. When you talk about large system then memory is an important factor. For example if you set text type for all text information it is highly a bad practice. So mysql has classified into different things. Like if you want to store the name you can use varchar(50), if you want to store address you can even use varchar(255). If you want to store the post or comment and description or any thing you can use text. If you want to use yes and no like information you can use char. I hope you understood.

滥情稳全场 2024-11-15 03:05:33

字符串类型的变体数量是进步的标志。在理想的世界中,旧的类型将被删除,新的和改进的类型将取代它们。但是,在现实世界中,传统兼容性要求字段类型的行为类似于 20 世纪 60 年代的 COBOL 字符串处理,以供需要它的应用程序使用。因此,char(20) 类型会填充尾随空格,就像 IBM 按键卡一样。

将各种子类型视为一组螺丝刀,有些小,有些大。每种方法的适用范围都很窄。如果您正在修理怀表,则不需要大螺丝刀。但如果应用是桥梁建设,那么微型精密螺丝刀就不会使用,而会使用大螺丝刀。数据库很像这样。

The number of variations for character string types is the sign of progress. In an ideal world, the old types would be removed and the new and improved types would replace them. But, in the real world, legacy compatibility requires fields types to, for example, behave like 1960s COBOL string handling for applications which expect it. So the char(20) type pads with trailing spaces to act like an IBM keypunch card.

Think of the various subtypes as a set of screwdrivers, some small, some big. Each has a narrow range of appropriate use. If you are working on a pocket watch, the big screwdrivers won't be needed. But if the application is bridge building, then the micro precision screwdrivers remain unused and the big ones get used. Databases are a lot like that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文