I am trying to create a table on mySQL console.
CREATE TABLE TRY (Essn int(10), Pno int(2), Hours DOUBLE(40,0));
When I try to add something to table:
INSERT INTO TRY ('123456789','1','32,5');
I got an error about syntax. I couldn't find the problem. Can anyone help?
1 Answer. “(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed.
DOUBLE is a double precision floating point number. MySQL uses eight bytes to store a DOUBLE value. MySQL treats DOUBLE as a synonym for DOUBLE PRECISION (a non-standard extension). In addition, MySQL also treats REAL as a synonym for DOUBLE PRECISION , unless the REAL_AS_FLOAT SQL mode is enabled.
Double Type Some data may take more digits to the right of the decimal point. While the storage size of the decimal type is variable, the double type takes 8 bytes storage size. Also double precision ranges up to fifteen decimal digits.
Float data can hold 8 bytes, or 15 places after the decimal point. Double data is similar to float, except that it allows for much larger numbers. They're used to specify precision, that is the number of whole numbers and number of digits shown after the decimal point of a complex number.
Get rid of the quote, replace 32,5 with 32.5, and add VALUES
keyword should work:
INSERT INTO TRY VALUES (123456789,1,32.5);
You might also want to change your double field definition for allowing more decimal numbers in Hours
field:
CREATE TABLE TRY (Essn int(10), Pno int(2), Hours DOUBLE(40,2));
refer to MySQL's approximate value section for more details
“(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed. MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With