Reputation: 525
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?
Upvotes: 6
Views: 49480
Reputation: 6138
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.
Upvotes: 7
Reputation: 21
In your creation, you defined that you do not want any digits saved after the decimal point. DOUBLE(40,0) means you have 40 digits and 0 of them after the decimal point.
Also see https://dev.mysql.com/doc/refman/5.6/en/floating-point-types.html for more information.
Upvotes: 2