Add AUTO_INCREMENT to an existing column
Let's first create
note
table without any column to have
AUTO_INCREMENT
CREATE TABLE note (
    id int,
    title varchar(50),
    description varchar(50),
    PRIMARY KEY(id, title)
);
After running the query above, we can add
AUTO_INCREMENT
feature to the existing column
id
ALTER TABLE note MODIFY id int NOT NULL AUTO_INCREMENT;
If the column is not
primary key
initially, we can modify the query, not to cause any error when adding
AUTO_INCREMENT
to it
CREATE TABLE note (
    id int,
    title varchar(50),
    description varchar(50)
);
Adding
AUTO_INCREMENT
feature to the column, that is not selected as a
primary key
ALTER TABLE note MODIFY id int NOT NULL PRIMARY KEY AUTO_INCREMENT
by Valeri Tandilashvili
4 years ago
MySQL
AUTO_INCREMENT
1
Pro tip: use ```triple backticks around text``` to write in code fences