Search code examples
mysqlwampauto-incrementcreate-table

MYSQL (WAMP SERVER): Error 1064 when using AUTO_INCREMENT=1000 to create table column?


I have this code: CREATE TABLE Company ( Comp_Code INT(5) NOT NULL AUTO_INCREMENT=1000, Comp_Name VARCHAR(15) NOT NULL, PRIMARY KEY (Comp_Code) ); but when i run it in MYSQL from WAMPServer it gives an error:

ERROR 1064 (42000): 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 '=1000, Comp_Name VARCHAR(15) NOT NULL, PRIMARY KEY (Comp_Code) )' at line 2

Why is this happening?


Solution

  • AUTO_INCREMENT is column option.

    Initial AUTO_INCREMENT=1000 value is table option.

    CREATE TABLE Company ( 
        Comp_Code INT(5) NOT NULL AUTO_INCREMENT,  -- specify that the column is AI
        Comp_Name VARCHAR(15) NOT NULL, 
        PRIMARY KEY (Comp_Code) 
    ) AUTO_INCREMENT=1000;                         -- specify initial AI value