Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which datatype to use to store a mobile number

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?

like image 508
sqlchild Avatar asked Jun 01 '11 07:06

sqlchild


1 Answers

  • 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)
like image 70
gbn Avatar answered Sep 22 '22 16:09

gbn