Adding
AUTO_INCREMENT
to any
varchar
column first requires the column to be converted into
int
CREATE TABLE note (
title varchar(50),
description varchar(50),
PRIMARY KEY(title)
);
INSERT INTO `note` (`title`, `description`) VALUES ('first', 'value'), ('second', 'value');
Let's add
AUTO_INCREMENT
to
title
column.
We are not able to add
AUTO_INCREMENT
without changing it's type to
int
ALTER TABLE note MODIFY title int NOT NULL AUTO_INCREMENT;
Note: In such cases If the table contains rows with string values, (for
AUTO INCREMENT
field) the string values will be replaced with numbers starting with 1