CREATE TABLE in MySQL syntax error

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 12:54:38

For double you have to add another digit after comma for precision.Also No space is allowed after name.the following script is working

 CREATE TABLE `Laptop` (
 `serial number` INT( 20 ) NOT NULL ,
 `Device Model` VARCHAR( 20 ) NOT NULL ,
 `Device Manufacturer` VARCHAR( 20 ) NOT NULL ,
 `Device Color` VARCHAR( 20 ) NOT NULL ,
 `Screen size` DOUBLE( 20,4 ) NOT NULL ,
 `Phone` DOUBLE( 20,4 ) NOT NULL ,
 `Id` INT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  UNIQUE (
 `serial number` 
  )
  ) ENGINE = innodb

DOUBLE requires precision too ( I gave DOUBLE(20,2) - change it as needed).

Plus there was a stray space at the end of serial number column name.

CREATE TABLE `Laptop` (
`serial number` INT( 20 ) NOT NULL ,
`Device Model` VARCHAR( 20 ) NOT NULL ,
`Device Manufacturer` VARCHAR( 20 ) NOT NULL ,
`Device Color` VARCHAR( 20 ) NOT NULL ,
`Screen size` DOUBLE( 20,2) NOT NULL ,
`Phone` DOUBLE( 20 ,2) NOT NULL ,
`Id` INT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
UNIQUE (
`serial number` 
)
) 

Also, it's better to use DECIMAL instead of DOUBLE as the doubles can't be represented exactly and creates problem while doing comparisons.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!