Search code examples
mysqlsqlsyntax-errorddlcreate-table

Having an error in sql while creating table


I am trying to create a table on my database. this is the error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') NOT NULL , `ctc` DOUBLE(5) NOT NULL , `ref` VARCHAR(50) NOT NULL , `date` D' at line 1

My query:

CREATE TABLE `job`.`form_details` ( 
    `email_id` VARCHAR(50) NOT NULL , 
    `name` VARCHAR(50) NOT NULL , 
    `number` VARCHAR(14) NOT NULL , 
    `city` VARCHAR(50) NOT NULL , 
    `skill` VARCHAR(50) NOT NULL , 
    `qualification` VARCHAR(50) NOT NULL , 
    `position` VARCHAR(50) NOT NULL , 
    `exp` DOUBLE(5) NOT NULL , 
    `ctc` DOUBLE(5) NOT NULL , 
    `ref` VARCHAR(50) NOT NULL , 
    `date` DATE NOT NULL , 
    `time stamp` TIMESTAMP(30) NOT NULL ) ENGINE = InnoDB;

Solution

  • A double's precision is specified by two arguments - (M, D) - M digits in total and D digits after the decimal point. A timestamp's precision must be no greater than 6. So:

    CREATE TABLE `job`.`form_details` (
     `email_id` VARCHAR(50) NOT NULL ,
     `name` VARCHAR(50) NOT NULL ,
     `number` VARCHAR(14) NOT NULL ,
     `city` VARCHAR(50) NOT NULL ,
     `skill` VARCHAR(50) NOT NULL ,
     `qualification` VARCHAR(50) NOT NULL ,
     `position` VARCHAR(50) NOT NULL ,
     `exp` DOUBLE(5, 2) NOT NULL , -- Two arguments for the double's precision
     `ctc` DOUBLE(5, 2) NOT NULL , -- Here too
     `ref` VARCHAR(50) NOT NULL ,
     `date` DATE NOT NULL ,
     `time stamp` TIMESTAMP(6) NOT NULL -- Timestamp precision capped at 6
    ) ENGINE = InnoDB