Out of range value for column 'contact_no' at row 1 - mysql

I was trying to add a number with a length of 11 but when I input it in the database it can't. If I try to add a number with a length of 10 it can.
This is the error:
ERROR 1264: 1264: Out of range value for column 'contact_no' at row 1
SQL Statement:
INSERT INTO `mcs`.`new_table` (`id`, `contact_no`) VALUES ('1', '12345678901')

It's not clear what question you are asking.
Why is this error being returned?
Likely, the contact_no column is declared with datatype of INT, a 32-bit integer, and you attempted to assign a value larger than the supported maximum value.
The maximum value for a signed 32-bit integer is 2,147,483,647. (that decimal value of 2^31-1. For an unsigned 32-bit integer, maximum value is 2^32.)
Some other question that wasn't asked
If you need to store values larger than the maximum supported by the INT datatype, you could define the column as a different datatype.
For example, BIGINT gives a maximum value of 2^63-1 for unsigned.
If you need a maximum of 12 decimal digits, you could use a DECIMAL(12) datatype.

Change your data type of contact_no to BIGINT.
Check range of different data type at MYSQL official website.
I personally recommend you to use varchar, as you don't need to compare contact number with any field.

Please check datatype of contact_no column.
'12345678901' is exceeding its size.

Related

Changing VARCHAR to INT or MEDIUMINT?

I have a field in my database table that is currently VARCHAR datatype but has numeric values in it so I want to change the data type. When I try to change it to MEDIUMINT, I get an error saying "#1265 - Data truncated for column 'fees' at row 1"
Any ideas how to change the data type? I'm using phpmyadmin to do this.
There may be beyond the range or may have string values in the column.
MEDIUMINT -8388608 to 8388607
https://dev.mysql.com/doc/refman/5.7/en/integer-types.html

MySQL Numeric Type

Hi I need to add a column to my table where I should insert a value that indicates the year relative to the row. So it will just be a number, always integer, always bigger than 0, always 4 digits... so what's the best numeric type for the column and how would the phh query to add the column would be?
Try the SMALLINT the minimum value is -32768 and the maximum value 32767 an interger can be used for bigger numbers between: -2147483648 and 2147483647
for example:
SMALINT(3)
means a number from -32768 until 32767 the (3) represents the display width of the field
I would suggest datatype YEAR()
Note: Values allowed in four-digit format: 1901 to 2155.
Otherwise SMALLINT() should be fine.
Statement would be:
ALTER TABLE table_name
ADD column_name datatype

Mysql INSERT recording wrong value

This must be a simple one but got no idea why is this happening.
Under this query:
INSERT INTO assist_reg (ar_id,ar_subid,ar_date) VALUES ('','2431052014','2014-05-31');
Field ar_subid on DDBB always records this value you can see on this screenshot:
ar_subid is a INT field with maximum of 20 characters, non-null with no predeterminate valur. this table is under UTF8-generalci.
http://dev.mysql.com/doc/refman/5.0/en/integer-types.html - you are exceeding the int data type's max value. You need a bigint

MYSQL inserting wrong info

I am inserting value
insert into user (name,fbid) Values ('Adi Mathur',100000564553314)
but in the database i see the value if fbid to be
2147483647
Why ? How should i fix it ?
fbid int(50)
As explained in the manual, the maximum value of a (signed) INT, which occupies 4 bytes/32 bits, is 2,147,483,647; for integer data types, the number in parenthesis is the display width, which only affects the way that the data is displayed, not how much space it is allocated for storage:
M indicates the maximum display width for integer types. For floating-point and fixed-point types, M is the total number of digits that can be stored (the precision). For string types, M is the maximum length. The maximum permissible value of M depends on the data type.
You probably want a BIGINT.

Why do values in the row I insert not match the values in the insert query?

I just can't understand why is my database (mysql) behaving like this! My console shows that the record is created properly (please, notice the "remote_id" value):
Tweet Create (0.3ms)
INSERT INTO `tweets` (`remote_id`, `text`, `user_id`, `twitter_account_id`)
VALUES (12325438258, 'jamaica', 1, 1)
But when I check the record, it shows that the remote_id is 2147483647 intead of the provided value (12325438258 in the example above)...
This table has many entries, but this field is always written with 2147483647... It was supposed to fill this space with an unique id (which I guarantee you is being generated properly).
That's because you're using the INT numeric type which has a limit of '2147483647', use BIGINT instead.
Source: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
My guess is that the value you are trying to insert is too large for the column. That number is suspicious in that it is the max value of a 32 bit signed integer.
Is the column type INT? To store that value you should make it a BIGINT. See Numeric Types from the MySQL manual.
As it is obvious you used a value with less size, so you need to use a larger type like BigInt ( and in application use long or int64