which datatype to use to store a mobile number

sqlchild picture sqlchild · Jun 1, 2011 · Viewed 54k times · Source

Which datatype shall I use to store mobile numbers of 10 digits (Ex.:9932234242). Shall I go for varchar(10) or for the big one- the "bigint".

If the number is of type- '0021-23141231' , then which datatype to use?

Answer

gbn picture gbn · Jun 1, 2011
  • varchar/char long enough for all expected (eg UK numbers are 11 long)
  • check constraint to allow only digits (expression = NOT LIKE '%[^0-9]%')
  • format in the client per locale (UK = 07123 456 789 , Switzerland = 071 234 56 78)