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