Solved

Is my CREATE TABLE syntax wrong?

Posted on 2010-11-15
6
738 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 42 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 42 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 4

Assisted Solution

by:max-hb
max-hb earned 41 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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