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

2023-11-28数据库问题
2

本文介绍了常见的 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 字段及其相应的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

MySQL GROUP BY DateTime +/- 3 秒
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)...
2024-04-16 数据库问题
14