-1

I'm begginer at MYSQL and I would like to ask you how it could be the best to format phone number in a database. I have table with phone numbers, those numbers indexes and a foreign key of users id. I want phone numbers to be autoincrementing for example 777 xxx xxx where x are i want to fill it with index of number. For example for index number 1 i will have 777 000 001 for index 2; 777 000 002 and so on. Any ideas?

  • Don't use an INT for a phone number. Read this question and its answers: https://stackoverflow.com/questions/24353778/which-is-best-data-type-for-phone-number-in-mysql-and-what-should-java-type-mapp – Bill Karwin Jan 25 '19 at 19:50
  • 1
    To add to @BillKarwin ‘s comment there is a standard E.164 for phone formats see https://dba.stackexchange.com/questions/104643/storing-phone-number-in-e-164.. instead off storing it in one column you can separated the formating like country code or the netcode in separated columns offcource when you want to be able to search more easy.. when selecting you can use concat to merge the data columns as one – Raymond Nijland Jan 26 '19 at 13:38

1 Answers1

0

You can set an intial value of 777000001. See this answer over here: How to set initial value and auto increment in MySQL?

Hope it helps.