Search code examples
mysqlmysql-error-1064

Syntax Error MYSQL 1064


I've had this error attempting to create a table that I just can't figure out. I'll try to explain it to the best of my abilities.

In the mysql command line, I'm entering

CREATE TABLE index(references INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(600), description VARCHAR(2500));

It repetitively gives me the 1064 error telling me something is wrong in the syntax that is near 'index(references INT NOT N... name VARCHAR(5600), des'.

I've tried renaming the table to random letters thinking it was possibly the name though no, any ideas anybody? I really would appreciate any help, thank you!

EDIT: My version does support VARCHAR's over 255 also. EDIT 2: Solved, renamed a couple data type names and the table name ^.^, thanks for everybody's help!


Solution

  • I know this gets through. Use back-ticks. And a typo on varchar.

    CREATE TABLE `index`
    (   `references` INT AUTO_INCREMENT PRIMARY KEY, 
        `name` VARCHAR(600), 
        `description` VARCHAR(2500)
    );
    

    Take a look at Mysql Reserved Words and Keywords

    Special care must always be used with the names with an (R) in that link. They need back-ticks. Better yet, choose another word/name.

    Edit: To answer one of your comment questions below.

    create table `table2`
    (
        `id` int auto_increment primary key,
        `colB` decimal(12,2) not null
    );
    
    insert table2 (colB) values (3.14),(100);
    
    select * from table2;
    +----+--------+
    | id | colB   |
    +----+--------+
    |  1 |   3.14 |
    |  2 | 100.00 |
    +----+--------+