?
Solved

Is my CREATE TABLE syntax wrong?

Posted on 2010-11-15
6
Medium Priority
?
740 Views
Last Modified: 2012-05-10
Is there a problem with my SQL syntax here, problem is pointing to the Double entry for some reason. I am using MySQL and HeidiSQL to create the table.

CREATE TABLE `wind_data` (
      `ID` INT(10) NOT NULL AUTO_INCREMENT,
      `DATE` DATE NULL DEFAULT NULL,
      `TIME` TIME NULL DEFAULT NULL,
      `DAT1` CHAR(10) NULL DEFAULT NULL,
      `WD` INT(3) NULL DEFAULT NULL,
      `WS` DOUBLE(10) NULL DEFAULT NULL,
      `DAT2` CHAR(10) NULL DEFAULT NULL,
      `DAT3` CHAR(10) NULL DEFAULT NULL,
      `DAT4` CHAR(10) NULL DEFAULT NULL,
      PRIMARY KEY (`ID`)
)
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
0
Comment
Question by:bhession
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Accepted Solution

by:
dsmile earned 168 total points
ID: 34135060
DO NOT specify length for DOUBLE datatype

CREATE TABLE `wind_data` (
      `ID` INT(10) NOT NULL AUTO_INCREMENT,
      `DATE` DATE NULL DEFAULT NULL,
      `TIME` TIME NULL DEFAULT NULL,
      `DAT1` CHAR(10) NULL DEFAULT NULL,
      `WD` INT(3) NULL DEFAULT NULL,
      `WS` DOUBLE NULL DEFAULT NULL,
      `DAT2` CHAR(10) NULL DEFAULT NULL,
      `DAT3` CHAR(10) NULL DEFAULT NULL,
      `DAT4` CHAR(10) NULL DEFAULT NULL,
      PRIMARY KEY (`ID`)
)
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
0
 
LVL 2

Assisted Solution

by:sunny-s
sunny-s earned 168 total points
ID: 34135061
try DOUBLE PRECISION instead of simple DOUBLE, maybe it would help.
0
 
LVL 13

Expert Comment

by:dsmile
ID: 34135072
Or you have to specify the number of digits after decimal point also

Try this

CREATE TABLE `wind_data` (
      `ID` INT(10) NOT NULL AUTO_INCREMENT,
      `DATE` DATE NULL DEFAULT NULL,
      `TIME` TIME NULL DEFAULT NULL,
      `DAT1` CHAR(10) NULL DEFAULT NULL,
      `WD` INT(3) NULL DEFAULT NULL,
      `WS` DOUBLE(10,2) NULL DEFAULT NULL,
      `DAT2` CHAR(10) NULL DEFAULT NULL,
      `DAT3` CHAR(10) NULL DEFAULT NULL,
      `DAT4` CHAR(10) NULL DEFAULT NULL,
      PRIMARY KEY (`ID`)
)
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 4

Assisted Solution

by:max-hb
max-hb earned 164 total points
ID: 34135073
Hi!
Defining double type columns requires you to specify a format "x,y" where y is the precision after decimal separator:
CREATE TABLE `test`.`wind_data` (
`ID` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`DATE` DATE NULL DEFAULT NULL ,
`TIME` TIME NULL DEFAULT NULL ,
`DAT1` CHAR( 10 ) NULL DEFAULT NULL ,
`WD` INT( 3 ) NULL DEFAULT NULL ,
`WS` DOUBLE( 10, 2 ) NULL DEFAULT NULL ,
`DAT2` CHAR( 10 ) NULL DEFAULT NULL ,
`DAT3` CHAR( 10 ) NULL DEFAULT NULL ,
`DAT4` CHAR( 10 ) NULL DEFAULT NULL ,
PRIMARY KEY ( `ID` )
) ENGINE = MYISAM ;

Open in new window

0
 
LVL 2

Expert Comment

by:sunny-s
ID: 34135089
also, note the MySQL needs two parameters after the word DOUBLE, or none, not one like you specified.

MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). Here, “(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.
0
 

Author Closing Comment

by:bhession
ID: 34135116
Great answering guys, you predicted my follow up questions as well.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question