Search code examples
mysqlsqlprimary-keyauto-incrementcreate-table

When issuing a command to MySQL, I'm getting that error "#1075 - Incorrect table definition;"


CREATE TABLE onscreen( 
   id int(2) not null AUTO_INCREMENT,
   subject varchar(100) not null,
   content varchar(100) not null,
   date datetime not null
);

Solution

  • The entire error message is:

    Incorrect table definition; there can be only one auto column and it must be defined as a key

    This is clear enough: MySQL requires that you define the auto-increment column as a primary key:

    CREATE TABLE onscreen( 
        id int(2) not null AUTO_INCREMENT primary key,  --> here
        subject varchar(100) not null, 
        content varchar(100) not null, 
        date datetime not null 
    )
    

    Demo on DB Fiddle