Which is best data type for phone number in MySQL and what should Java type mapping for it be?

后端 未结 10 1577
有刺的猬
有刺的猬 2020-12-04 11:09

I am using MySQL with Spring JDBC template for my web application. I need to store phone number with only digits (10). I am little bit confused about data type using data ty

相关标签:
10条回答
  • 2020-12-04 11:51

    you can use var-char,String,and int ,it depends on you, if you use only country code with mobile number than you can use int,if you use special formate for number than use String or var-char type, if you use var-char then must defile size of number and restrict from user.

    0 讨论(0)
  • 2020-12-04 11:54

    It's all based on your requirement. if you are developing a small scale app and covers only specific region (target audience), you can choose BIGINT to store only numbers since VARCHAR consumes more byte than BIGINT ( having optimal memory usage design matters ). but if you are developing a large scale app and targets global users and you have enough database capabilities to store data, you can definitely choose VARCHAR.

    0 讨论(0)
  • 2020-12-04 11:55

    Consider using the E.164 format. For full international support, you'd need a VARCHAR of 15 digits.

    See Twilio's recommendation for more information on localization of phone numbers.

    0 讨论(0)
  • 2020-12-04 11:57
    1. String
    2. Varchar

    This is my opinion for my database as recommended by my mentor

    0 讨论(0)
提交回复
热议问题