Question

I have a table with many columns. Between them there are AB and AL both decimal(14,3) . Now I have to create a new table like this:

create table new as
select AB, AL, (AB/AL)*100 AS M from my_table;

Mysql give me some warnings like: "1265 Data truncated for column M at row 2".

Is it warning me that the new number will be rounded? Is it safe?

Now the new column M is a decimal(24,7) but I need only a rounded DECIMAL(14, 3). Do I have to do an alter table or there is a way to do that in the create statement?

I have a huge database with many columns like these so I need to keep the table size minim

Was it helpful?

Solution

Just do the maths an example 1.0 / 0.3 are both ok for a decimal(14,3) but their result when applied with your formula produces 333.333333....

there likely will be rounding errors but only minor ones if you only need 14,3 just use 14,3 as convering a 24,7 to a 14,3 will be the same as just making a 14,3.

Your data will be truncated, but not likely enough for it to effect you, Trial it first to be safe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top