?
Solved

Is my CREATE TABLE syntax wrong?

Posted on 2010-11-15
6
Medium Priority
?
743 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
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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

755 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