简体   繁体   English

将电话号码存储在SQL数据库中

[英]Storing phone numbers in a SQL database

I have a table that stores mobile numbers 我有一张桌子,存储手机号码

it stores 它存储
country 国家
network 网络
the rest 其余的部分

so an example mobile, or masked is 因此,移动或蒙版的示例是

64 21 8229918  
CC NN XXXXXXX

Now, 现在,

Country makes sense to be called country 国家被称为国家
Network to be called Network 网络称为网络

But what would you call the rest? 但是剩下的又叫什么呢?

I am redesigning the database so I want this to be as accurately named as possible. 我正在重新设计数据库,所以我希望它尽可能准确地命名。 I can use multiple words in camel case. 我可以在骆驼的情况下使用多个单词。

Any ideas? 有任何想法吗?

also, 也,

A country code is only ever digits, and I believe at most 4? 国家/地区代码只能是数字,我相信最多为4位?
so should I use type int? 所以我应该使用int类型吗?
same applies for network. 同样适用于网络。

and what about the rest? 那剩下的呢?

I have no idea how long it could get... 我不知道它能持续多久...

I would try to keep it as simple as possible. 我会尽量保持简单。 Separate only the country code and the number, and store them both as text. 仅将国家/地区代码和数字分开,并将它们都存储为文本。 Because different countries use different numbering schemes , it would be impossible to figure out what a "network" is (or what that might even mean) for every country. 因为不同的国家使用不同的编号方案 ,所以不可能弄清楚每个国家的“网络”是什么(甚至可能意味着什么)。

For this reason, it's best to just store the country code in one field and the phone number in another, both as text, with no formatting or spaces. 因此,最好仅将国家/地区代码存储在一个字段中,将电话号码存储在另一个字段中,二者都应为文本,且不带格式或空格。 You also might want to allocate another field for the "extension", but I'm not sure how usage or notation of extensions varies by country. 您可能还想为“扩展名”分配另一个字段,但是我不确定扩展名的使用或表示方式因国家/地区而异。 You can't just use integers, because country codes and some countries' phone numbers can start with 0. 您不能只使用整数,因为国家/地区代码和某些国家/地区的电话号码可以以0开头。

Based on Wikipedia, the longest country code is three characters. 根据Wikipedia,最长的国家/地区代码为三个字符。 So you would only need three digits there. 因此,您只需要三位数。 I personally would allocate about 16 characters for the number itself, to ensure that every numbering plan is covered fully. 我个人将为该数字分配大约16个字符,以确保充分覆盖每个编号计划。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM