I created a table in a database in MySQL with a decimal colu

I created a table in a database in MySQL with a decimal column (1,1), in order to input a student\'s GPA. However, it is giving me an out of bounds error (Error Code: 1264. Out of range value for column \'GPA\' at row 1) when I try to insert a value into it (insert into student(sID,sName,GPA,sizeHS)values (123,\"Amy\",3.9,1000)). I\'m not sure if I entered in the data wrong, or defined the GPA value wrong.

Solution

Yes ofcourse you did it wrong. But not with the data. Its with the declaration. When declaring decimal values in the DDL statement, you have to declare the size of the floating point number. Here decimal is the data type, and the 2 values you pass in the braces is: the first part is the total number of digits, and the second part is out of total number of digits, how many are dedicated to represent the mantissa. So, if you want values from 0.0 to somewhere around 4.0 or so, you have to declare the decimal as: decimal column(2, 1); Here 2 represents the total number of digits, and 1 represents the mantissa. Which means, 1 digit is for integral representation, and the other for mantissa.

I created a table in a database in MySQL with a decimal column (1,1), in order to input a student\'s GPA. However, it is giving me an out of bounds error (Error

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site