int take just 2147483647, I want 9999999999 - mysql

In MYSQL database I took phone.no column and it's data type int. I take it from int(13) to int(30) but it's max value is 2147483647. I want max value to be 9999999999.

It is not recommended to use INT(or numeric datatype) for Phone Numbers. The max value of int is 2147483647 so you cannot use more than that in it.
Also it would be better to use varchar to store phone number instead of int or bigint. You can use varchar(15) and certainly create index on that field. Also check Telephone Numbers on wikipedia.
Reason to use varchar instead of Int for phone numbers could be:-
You are not going to perform any arithmetic operation(+,-,*,/) on phone number fields so using varchar is a good option in my opinion.
Lets say you want to store the phone numbers in international format like +4412345667 or like (1234) 23456 then varchar would be better option.
If you want to compare two phone numbers like 00789768 and 0789768 then with the int datatype both will be equal but with varchar they are treated as two different phone numbers.

INT has a maximum value of 2147483647. You will need to use BIGINT if you want a larger size, but for phone numbers, a VARCHAR is a better option.

In Mysql your change : " int(13) to int(30) "
only affect representation on selects and not on the size of the column when applied on on ints . (correct only for varchars)
What you needed as stated in the previous answers use the big int type.
In any case when discussing phone numbers ints are not really a good choice. When comparing ints 008877 and 00008877 are the same. So a better design choice will be to use a varchar with the correct size.

We should always use Varchar() for storing Phone number instead of integer or bigint.

Related

Vb.net using mysql as back end [duplicate]

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 contact_user
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
contact INT(10)
)
Now the problem is that if I insert a 10 mobile no.(e.g.9595891256) using phpmyadmin into contact field it will insert some random value and shows a warning saying "data out of column range"
But if I insert a simple 10 digit no (e.g.4561327894) then it works well and no warning is shown.
SO please tell me what is the issue in inserting a mobile no in this column?
I am using mysql 5.1 on ubuntu 11.04 and also using phpmyadmin.
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.
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.
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.

Fixed length numeric value - BIGINT or CHAR data type?

I have a couple numeric fields which will be storing fixed length numeric values, I don't need to do any math on these fields or sorting by highest to lowest or anything like that, so I'm wondering if using the CHAR data type would be better than using a BIGINT?
If you have a fixed-width number and it fits in a decimal field, then use that data type. Something like decimal(15, 0) should give you want you want.
If the choice is between a fixed width character and a string, I would probably go with a string in this case. I find that char(15) makes more sense than storing a 15-digit number in a bigint field. This makes it clear that the field is really an identifier of some sort, rather than an actual number.
If the data is numeric, use a numeric field. You never know when your requirements will change and you'll need to do numeric processing on the field.

MySQL char vs. int

I'm currently having a discussion in my class about the datatypes char and int in MySQL.
We have a phone number of 8 individual numbers. However, we can't find any pros and cons for each of them.
Should we use the char type or the int type, and why?
If you have a fixed size then you can use char(8) -> 8B , mysql works much faster with fixed size fields, but if you chose int -> 4B you will save space and also if you will have a index on that field it will work faster then the char.
You can do a simple benchmark to test the speed of writes and reads using char(8) and int
There is no point in using variable length type like varchar or varbinary if you have a fixed size because performance will decrease
Depends on how you want to represent the phone number, do you need area codes, country codes and stuff like that, and do you want to save it as a single column or do you want to split it up?
Personally, I would choose to represent area codes, country codes, and the phone number as 3 columns with the datatype int, as this would make it easier to find all phone numbers in one area, and so on. But if it's only purpose is to be a like a string value, the char would be sufficient, however i would consider using the varchar instead, if you have phone numbers for several countries.`
Don't know about the US exactly, but in Europe the national access code is a leading 0 , and international access code is a leading 00 or +. So that's a con to using INT, as the leading 0's would be lost. Further more you also have phone numbers that contain names and even though these names can be converted to numbers, it would probably be nice to keep them as a name. That's a second con to using INT. Last con is you can also have extension numbers, etc. All goes into favor of VARCHAR.
I started using VARCHAR for storing phone numbers because it gives you more range in formats of different countries. Storage is cheap.

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

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 contact_user
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
contact INT(10)
)
Now the problem is that if I insert a 10 mobile no.(e.g.9595891256) using phpmyadmin into contact field it will insert some random value and shows a warning saying "data out of column range"
But if I insert a simple 10 digit no (e.g.4561327894) then it works well and no warning is shown.
SO please tell me what is the issue in inserting a mobile no in this column?
I am using mysql 5.1 on ubuntu 11.04 and also using phpmyadmin.
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.
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.
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.

What does `unsigned` in MySQL mean and when to use it?

What does "unsigned" mean in MySQL and when should I use it?
MySQL says:
All integer types can have an optional
(nonstandard) attribute UNSIGNED.
Unsigned type can be used to permit
only nonnegative numbers in a column
or when you need a larger upper
numeric range for the column. For
example, if an INT column is UNSIGNED,
the size of the column's range is the
same but its endpoints shift from
-2147483648 and 2147483647 up to 0 and 4294967295.
When do I use it ?
Ask yourself this question: Will this field ever contain a negative value?
If the answer is no, then you want an UNSIGNED data type.
A common mistake is to use a primary key that is an auto-increment INT starting at zero, yet the type is SIGNED, in that case you’ll never touch any of the negative numbers and you are reducing the range of possible id's to half.