Wyner Wyner - 4 months ago 13
SQL Question

MySQL Error Number. 1064

CREATE TABLE `smdonation`, `SM_USERLOGIN` {
`SM_ID` INTEGER NOT NULL DEFAULT,
`SM_USERNAME` VARCHAR(15) NOT NULL DEFAULT '',
`SM_PASSWORD` VARCHAR(20) NOT NULL DEFAULT '',
`SM_NAME` VARCHAR (50) NOT NULL DEFAULT '',
`SM_AGE` INTEGER NOT NULL DEFAULT,
`SM_EMAI`L VARCHAR(50) NOT NULL DEFAULT '',
PRIMARY KEY(SM_ID)
} ENGINE = InnoDB;


When trying to create the above table, I get the below error:


MySQL Error Number. 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
SM_USERNAME
VARCHAR(15) NOT NULL DEFAULT ",
SM_PASSWORD
VARCHAR(20)' a line 2


Initially I tried with
TYPE=InnoDB
that failed, so search in internet and I replace to
ENGINE=InnoDB
to create the table, but the error still exist.

The error in the screenshot:

The error

Answer

3 Issues in your code:

  1. You missed the Default values for integer
  2. Table creation should not contain the comma in it, it should be schemaname.tablename
  3. Table creation should contain the parenthesis ( and not {

So your working code would be:

CREATE TABLE `smdonation`.`SM_USERLOGIN` (
    `SM_ID` INTEGER NOT NULL DEFAULT 0, 
    `SM_USERNAME` VARCHAR(15) NOT NULL DEFAULT '', 
    `SM_PASSWORD` VARCHAR(20) NOT NULL DEFAULT '', 
    `SM_NAME` VARCHAR (50) NOT NULL DEFAULT '', 
    `SM_AGE` INTEGER NOT NULL DEFAULT 0, 
    `SM_EMAIL` VARCHAR(50) NOT NULL DEFAULT '', 
    PRIMARY KEY(SM_ID) 
) ENGINE = InnoDB;
Comments