What is the issue with 10 digit mobile no data in mysql?

前端 未结 3 854
半阙折子戏
半阙折子戏 2021-01-15 13:38

I made a table for storing contact record of user of my website. It also contains a 10 digit mobile no.

Table structure is like this:

CREATE TABLE co         


        
相关标签:
3条回答
  • 2021-01-15 13:47

    The maximum value for an INT in MySQL is 2147483647 (or 4294967295 if unsigned), according to the MySQL documentation. If your value exceeds this limit, you integer will overflow, hence the not-that-random value.

    Also, INT is not the best solution to store phone numbers. You might lose leading zeros if they are one or more. Also, international phone numbers start with a + sign. Consider using a VARCHAR. This will end up using more space in the database, but will provide more consistency.

    0 讨论(0)
  • 2021-01-15 13:56

    INT(10) does not mean a 10-digit number, it means an integer with a display width of 10 digits. Whether you put INT(2) or INT(10), MySQL still only stores an (unsigned, in this case) INT which has a maximum value of 4294967295.

    You can use a BIGINT instead of INT to store it as a numeric. I wouldn't recommend this, however, because it won't allow for international numbers. If you are certain your application will only use US numbers, using BIGINT will save you 3 bytes per row over VARCHAR(10) -- if that sort of thing concerns you.

    Since it is a phone number (and therefore you won't be doing numeric calculations against it), try using a VARCHAR(20). This allows you the ability to store international phone numbers properly, should that need arise.

    0 讨论(0)
  • 2021-01-15 14:04

    It is because of the max size of type INT you need to use a different type to hold a number that large. Try using BIGINT.

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