Mysql INSERT recording wrong value - mysql

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

Related

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 table column datatype medium int not working

I have problem with one of my mysql table datatype. In that table i have a column stokid, for this i gave data type as medium int.It works fine with upto this number 8141114 i mean when i run a insert query it inserts corrctly. But when i try to run a
insert query with 9041214 this number i am getting some different number in that column --- 8388607
After that i changed that column type as int . Now its working fine. But when it was medium int why it was not worked? Can some one please clarify this one?
Read the documentation; MEDIUMINT has a maximum value of 8388607 signed. Alter the type to INT for a higher maximum value.

Create a computed column based on another column in MySQL

I have a 2 columns in my table: a varchar(8) and an int.
I want to auto-increment the int column and when I do, I want to copy the value into the varchar(8) column, but pad it with 0's until it is 8 characters long, so for example, if the int column was incremented to 3, the varchar(8) column would contain '00000003'.
My two questions are, what happens when the varchar(8) column gets to '99999999' because I don't want to have duplicates?
How would I do this in MySQL?
If my values can be between 00000000 to 99999999, how many values can i have before I run out?
This is my alternative approach to just creating a random 8 character string and checking MySQL for duplicates. I thought this was a better approach and would allow for a greater number of values.
Because your formatted column depends upon, and is derivable from, the id column, your table design violates 3NF.
Either create a view that has your derived column in it (see this in sqlfiddle):
CREATE VIEW myview AS
SELECT *, substring(cast(100000000 + id AS CHAR(9)), 2) AS formatted_id
FROM mytable
or just start your auto-increment at 10000000, then it will always be 8 digits long:
ALTER TABLE mytable AUTO_INCREMENT = 10000000;
Simple, if the column is unique, it will throw an exception telling that the value already do exists. But if not unique, after 99999999 you'll get error message that the value is truncated.
Alternatives, why not use INT AUTO_INCREMENT? or a custom ID with a combination of date/time, eg
YYMMDD-00000
This will have a maximum record of 99999 records per day. It will reset on the next day.

two column primary key in mysql returning error and general funnyness

I have created a two column key in my mysql db (app_id, dated) and when i run the following query i get a problem
INSERT INTO `facebook_application_shares` (`user_id`, `app_id`, `dated`, `stats`) VALUES ('80', '269456199802533', '2012-04-24', '0')
I get the following error- even though the app_id is 269456199802533 and not 2147483647
Duplicate entry '2147483647-2012-04-24' for key 1
and then when i check the actual db table the value is actually "2147483647"
I am very much confused by this
2147483647, or 0x7FFFFFFF, is the greatest number MySQL is able to store in an INT SIGNED column (which you app_id seems to be). Greater values just get truncated to it.
Make your app_id a BIGINT UNSIGNED.
Note that INT(100) is still a 4-bit integer, with an optional hint to an application not to show more than 100 digits from it:
This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)
It's not that it is really able to store a googol - 1.

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