Changing VARCHAR to INT or MEDIUMINT? - mysql

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

Related

ID Gets changed because out of range value of datatype Big Int

I am getting this error in mySQL database.
I have a table where I have take ID column & its data type set BIGINT & values to 100.
Now I am trying to pass this ID (110585777261232376048) under but it gets changed to this (9223372036854775807).
I can't change length of my ID since its auto-generated dynamic value.
How do I change my column properties to make it work correctly?
BIGINT unsigned can take a range of 0 to 18,446,744,073,709,551,615. Try setting the column as UNSIGNED BIGINT .. It cannot accept a value beyond this. You need to convert the datatype to DOUBLE if the range exceeds this limit

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

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.

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

Converting datatypes in mysql

This might be a very general question but i have a doubt in this.
As a beginner I was unsuccessful in trying to insert rows into table B by selecting from table A .
A field from table A has DECIMAL datatype and its corresponding field in table B has
BIGINT datatype. Can a value with DECIMAL datatype be inserted in a field with BIGINT datatype?
To my knowledge ... No ... Big int is pretty much the same as INT just that the range is higher. It takes integer values 0 to 18446744073709551615.
More information here

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