数据库中的电话号码列 [英] Phone Number Columns in a Database

查看:229
本文介绍了数据库中的电话号码列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去3家公司中,电话号码列的类型为varchar(n)。原因是他们可能想要存储扩展名(ext。333)。但在每种情况下, - 字符在插入和更新时都会被删除。我不明白为什么.ext字符可以存储,但不是 - 字符。有没有人看到这个,你能想到这样做的解释吗?如果你想要存储的是数字,那么你最好不要使用int字段?相反,如果你想把数字存储为字符串/ varchar,那么为什么不保留所有的字符,不打扰格式化显示和清理写?

In the last 3 companies I've worked at, the phone number columns are of type varchar(n). The reason being that they might want to store extensions (ext. 333). But in every case, the "-" characters are stripped out when inserting and updating. I don't understand why the ".ext" characters are okay to store but not the "-" character. Has any one else seen this and what explanation can you think of for doing it this way? If all you want to store is the numbers, then aren't you better off using an int field? Conversely, if you want to store the number as a string/varchar, then why not keep all the characters and not bother with formatting on display and cleaning on write?

我也有兴趣了解其他地方实施电话号码存储的其他方式。

I'm also interested in hearing about other ways in which phone number storage is implemented in other places.

推荐答案

快速测试:你要添加/减少/乘/除电话号码吗?不。与SSN类似,电话号码是可以包含实际数字的离散数据,因此字符串类型可能是最合适的。

Quick test: are you going to add/subtract/multiply/divide Phone Numbers? Nope. Similarly to SSNs, Phone Numbers are discrete pieces of data that can contain actual numbers, so a string type is probably most appropriate.

这篇关于数据库中的电话号码列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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