View Full Version : MySQL and floating point
dc2000
06-26-2006, 02:26 AM
Hello:
I'm trying to create a table with a price column in MySQL database using DOUBLE type but it returns an error. Here's SQL line:
CREATE TABLE units (id INT AUTO_INCREMENT PRIMARY KEY, id_group INT, price DOUBLE, desc TINYTEXT, stat INT)
What could be the problem?
BearState
06-26-2006, 03:13 PM
What is the error?
I don't usually declare Primary Key where you did here.
At the moment, I don't even know if that is correct syntax.
Don't forget that semicolon;
:)
dc2000
06-26-2006, 03:51 PM
You know, I'm not really good in SQL. What do you mean about semicolon?
The error I get from that sample is:
MySQL #1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc TINYTEXT, stat INT) VALUES('1','350' at line 1'
How would you write this MySQL line?
BearState
06-26-2006, 06:10 PM
desc ( descending ) is a restricted keyword used in the order by clause.
You may not use it as a field name w/o begging for trouble.
The corresponding keyword is 'asc' for ascending.
And actually, you are pushing it with 'stat' also. For sure, status is a restricted keyword, but it may be possible that some RDBMS may have a 'stat' command and stat would be restricted.
The semicolon may not be necessary where you are using it, but just good habit to use it.
dc2000
06-26-2006, 06:53 PM
Hey, thanks! So the issue is not with DOUBLE? How can I resolve this naming issue? What kind of quotes do I need to use?
BearState
06-26-2006, 07:02 PM
Use alter table to change the field name from desc to something else. Then go through your code and make the changes where necessary.
Reference your MYSQL manual in the future to determine whether you will be using a keyword before naming fields and variables.
Quotes?
"What's the matter that you read?" asked Polonius.
"Words." replied Hamlet.
"How pregnant are his replies?!" Polonius notes.
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.