Unable to add AUTO INCREMENT without selecting the field as a PRIMARY KEY
It's not possible to add
AUTO_INCREMENT
feature to a column that is not selected as a primary key. If we want to add the feature to a column, we must make it primary key
CREATE TABLE note (
    id int AUTO_INCREMENT,
    title varchar(50),
    description varchar(50)
);
After running the above query, the following error will be generated:
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
The correct syntax of the query after adding primary key to the column
id
:
CREATE TABLE note (
    id int AUTO_INCREMENT,
    title varchar(50),
    description varchar(50),
    PRIMARY KEY (id)
);
by Valeri Tandilashvili
4 years ago
MySQL
CREATE TABLE
AUTO_INCREMENT
1
Pro tip: use ```triple backticks around text``` to write in code fences