常见的 MySQL 字段及其相应的数据类型

Common MySQL fields and their appropriate data types(常见的 MySQL 字段及其相应的数据类型)
本文介绍了常见的 MySQL 字段及其相应的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个非常小的 MySQL 数据库,用于存储名字、姓氏、电子邮件和电话号码,并且正在努力为每个字段找到完美"的数据类型.我知道没有完美的答案,但是对于诸如此类的常用领域,必须有某种通用约定.例如,我确定一个未格式化的美国电话号码太大而不能存储为 unsigned int,它必须至少是一个 bigint.

I am setting up a very small MySQL database that stores, first name, last name, email and phone number and am struggling to find the 'perfect' datatype for each field. I know there is no such thing as a perfect answer, but there must be some sort of common convention for commonly used fields such as these. For instance, I have determined that an unformatted US phone number is too big to be stored as an unsigned int, it must be at least a bigint.

因为我相信其他人可能会觉得这很有用,所以我不想将我的问题仅限于我上面提到的领域.

Because I am sure other people would probably find this useful, I dont want to restrict my question to just the fields I mentioned above.

哪些数据类型适合常见的数据库字段?电话号码、电子邮件和地址等字段?

What datatypes are appropriate for common database fields? Fields like phone number, email and address?

推荐答案

有人会发布比这更好的答案,但只是想说明我个人永远不会在任何类型的整数字段中存储电话号码,主要是因为:

Someone's going to post a much better answer than this, but just wanted to make the point that personally I would never store a phone number in any kind of integer field, mainly because:

  1. 你不需要用它做任何算术运算,并且
  2. 迟早有人会尝试(做类似的事情)在他们的区号周围加上括号.

但总的来说,我似乎几乎只使用:

In general though, I seem to almost exclusively use:

  • INT(11) 用于 ID 或引用另一个 ID 的任何内容
  • 时间戳的日期时间
  • VARCHAR(255) 用于保证少于 255 个字符的任何内容(页面标题、名称等)
  • 几乎所有其他内容的文本.

当然也有例外,但我发现这涵盖了大多数可能性.

Of course there are exceptions, but I find that covers most eventualities.

这篇关于常见的 MySQL 字段及其相应的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)