Storing phone numbers in a SQL database
I have a table that stores mobile numbers
it stores
country network the restso an example mobile, or masked is
64 21 8229918 CC NN XXXXXXX
Now,
Country makes sense to be called country
Network to be called NetworkBut 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?
so should I use type 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.
Based on Wikipedia, the longest country code is three characters. 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.
精彩评论